Skip to content

Commit d980f28

Browse files
989073-EndColumnPivotTable
1 parent e9f5f6e commit d980f28

3 files changed

Lines changed: 88 additions & 78 deletions

File tree

Document-Processing-toc.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6368,6 +6368,9 @@
63686368
<li>
63696369
<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>
63706370
</li>
6371+
<li>
6372+
<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>
6373+
</li>
63716374
<li>
63726375
<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>
63736376
</li>

Document-Processing/Excel/Excel-Library/NET/Pivot-Table/Pivot-Table-Options.md

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -334,81 +334,4 @@ End Using
334334
{% endhighlight %}
335335
{% endtabs %}
336336

337-
A complete working example to add calculated field in pivot table in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Pivot%20Table/Calculated%20Field/.NET/Calculated%20Field).
338-
339-
### Get PivotTable end column
340-
341-
To obtain a PivotTable's end column, call PivotTable.Layout(), then read the EndLocation property from the implementation type. The EndLocation range's LastColumn value is the pivot table's last column index.
342-
343-
{% tabs %}
344-
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Pivot%20Table/End%20Column/.NET/End%20Column/End%20Column/Program.cs,180" %}
345-
using (ExcelEngine excelEngine = new ExcelEngine())
346-
{
347-
IApplication application = excelEngine.Excel;
348-
application.DefaultVersion = ExcelVersion.Xlsx;
349-
350-
// Open workbook (update path as needed)
351-
IWorkbook workbook = application.Workbooks.Open("PivotTable.xlsx");
352-
353-
// Get the first pivot table
354-
IPivotTable pivotTable = workbook.Worksheets[0].PivotTables[0];
355-
356-
// Ensure layout is calculated
357-
pivotTable.Layout();
358-
359-
// Read EndLocation from the implementation type
360-
IRange endRange = (pivotTable as Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation;
361-
int lastColumn = endRange.LastColumn;
362-
363-
// Use lastColumn as needed (e.g., log)
364-
Console.WriteLine("PivotTable last column: " + lastColumn);
365-
}
366-
{% endhighlight %}
367-
368-
{% highlight c# tabtitle="C# [Windows-specific]" %}
369-
using (ExcelEngine excelEngine = new ExcelEngine())
370-
{
371-
IApplication application = excelEngine.Excel;
372-
application.DefaultVersion = ExcelVersion.Xlsx;
373-
374-
// Open workbook (update path as needed)
375-
IWorkbook workbook = application.Workbooks.Open("PivotTable.xlsx");
376-
377-
// Get the first pivot table
378-
IPivotTable pivotTable = workbook.Worksheets[0].PivotTables[0];
379-
380-
// Ensure layout is calculated
381-
pivotTable.Layout();
382-
383-
// Read EndLocation from the implementation type
384-
IRange endRange = (pivotTable as Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation;
385-
int lastColumn = endRange.LastColumn;
386-
387-
// Use lastColumn as needed (e.g., log)
388-
Console.WriteLine("PivotTable last column: " + lastColumn);
389-
}
390-
{% endhighlight %}
391-
392-
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
393-
Using excelEngine As New ExcelEngine()
394-
Dim application As IApplication = excelEngine.Excel
395-
application.DefaultVersion = ExcelVersion.Xlsx
396-
397-
' Open workbook (update path as needed)
398-
Dim workbook As IWorkbook = application.Workbooks.Open("PivotTable.xlsx")
399-
400-
Dim pivotTable As IPivotTable = workbook.Worksheets(0).PivotTables(0)
401-
402-
' Calculate layout
403-
pivotTable.Layout()
404-
405-
' Read EndLocation from implementation and get last column
406-
Dim endRange As IRange = DirectCast(pivotTable, Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation
407-
Dim lastColumn As Integer = endRange.LastColumn
408-
409-
Console.WriteLine("PivotTable last column: " & lastColumn)
410-
End Using
411-
{% endhighlight %}
412-
{% endtabs %}
413-
414-
A complete working example to get the end column of a pivot table in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Pivot%20Table/End%20Column/.NET/End%20Column).
337+
A complete working example to add calculated field in pivot table in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Pivot%20Table/Calculated%20Field/.NET/Calculated%20Field).
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)