Skip to content

Commit 6aa702e

Browse files
authored
Merge pull request #2282 from syncfusion-content/989073-EndColumnPivotTable
Documentation (989073): UG for how to get the end column of a PivotTable?
2 parents 2e949fc + 8c30b04 commit 6aa702e

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

Document-Processing-toc.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6370,6 +6370,9 @@
63706370
<li>
63716371
<a href="/document-processing/excel/excel-library/net/faqs/how-to-retrieve-the-list-of-named-ranges-in-an-Excel-workbook">How to retrieve the list of named ranges in an Excel workbook?</a>
63726372
</li>
6373+
<li>
6374+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-identify-the-end-column-of-a-pivottable-in-excel">How to identify the end column of a PivotTable in Excel?</a>
6375+
</li>
63736376
<li>
63746377
<a href="/document-processing/excel/excel-library/net/faqs/how-to-extract-embedded-OLE-files-from-an-Excel-workbook-as-streams">How to extract embedded OLE files from an Excel workbook as streams?</a>
63756378
</li>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: Identify the end column of a PivotTable in Excel | Syncfusion
3+
description: Code example to identify the end column of a PivotTable in an Excel workbook using the Syncfusion .NET Excel library (XlsIO).
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to identify the end column of a PivotTable in Excel?
10+
11+
The following code examples demonstrate how to identify the end column of a PivotTable in an Excel workbook using C# (Cross-platform and Windows-specific) and VB.NET.
12+
13+
{% tabs %}
14+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Pivot%20Tables%20End%20Column/.NET/End%20Column/End%20Column/Program.cs,180" %}
15+
using (ExcelEngine excelEngine = new ExcelEngine())
16+
{
17+
IApplication application = excelEngine.Excel;
18+
application.DefaultVersion = ExcelVersion.Xlsx;
19+
20+
// Open workbook (update path as needed)
21+
IWorkbook workbook = application.Workbooks.Open("PivotTable.xlsx");
22+
23+
// Get the first pivot table
24+
IPivotTable pivotTable = workbook.Worksheets[0].PivotTables[0];
25+
26+
// Ensure layout is calculated
27+
pivotTable.Layout();
28+
29+
// Read EndLocation from the implementation type
30+
IRange endRange = (pivotTable as Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation;
31+
int lastColumn = endRange.LastColumn;
32+
33+
// Use lastColumn as needed (e.g., log)
34+
Console.WriteLine("PivotTable last column: " + lastColumn);
35+
}
36+
{% endhighlight %}
37+
38+
{% highlight c# tabtitle="C# [Windows-specific]" %}
39+
using (ExcelEngine excelEngine = new ExcelEngine())
40+
{
41+
IApplication application = excelEngine.Excel;
42+
application.DefaultVersion = ExcelVersion.Xlsx;
43+
44+
// Open workbook (update path as needed)
45+
IWorkbook workbook = application.Workbooks.Open("PivotTable.xlsx");
46+
47+
// Get the first pivot table
48+
IPivotTable pivotTable = workbook.Worksheets[0].PivotTables[0];
49+
50+
// Ensure layout is calculated
51+
pivotTable.Layout();
52+
53+
// Read EndLocation from the implementation type
54+
IRange endRange = (pivotTable as Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation;
55+
int lastColumn = endRange.LastColumn;
56+
57+
// Use lastColumn as needed (e.g., log)
58+
Console.WriteLine("PivotTable last column: " + lastColumn);
59+
}
60+
{% endhighlight %}
61+
62+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
63+
Using excelEngine As New ExcelEngine()
64+
Dim application As IApplication = excelEngine.Excel
65+
application.DefaultVersion = ExcelVersion.Xlsx
66+
67+
' Open workbook (update path as needed)
68+
Dim workbook As IWorkbook = application.Workbooks.Open("PivotTable.xlsx")
69+
70+
Dim pivotTable As IPivotTable = workbook.Worksheets(0).PivotTables(0)
71+
72+
' Calculate layout
73+
pivotTable.Layout()
74+
75+
' Read EndLocation from implementation and get last column
76+
Dim endRange As IRange = DirectCast(pivotTable, Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation
77+
Dim lastColumn As Integer = endRange.LastColumn
78+
79+
Console.WriteLine("PivotTable last column: " & lastColumn)
80+
End Using
81+
{% endhighlight %}
82+
{% endtabs %}
83+
84+
A complete working example to identify the end column of a pivot table in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Pivot%20Tables%20End%20Column/.NET/End%20Column).

0 commit comments

Comments
 (0)