Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6368,6 +6368,9 @@
<li>
<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>
</li>
<li>
<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>
</li>
<li>
<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>
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
title: Identify the end column of a PivotTable in Excel | Syncfusion
description: Code example to identify the end column of a PivotTable in an Excel workbook using the Syncfusion .NET Excel library (XlsIO).
platform: document-processing
control: XlsIO
documentation: UG
---

# How to identify the end column of a PivotTable in Excel?

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.

{% tabs %}
{% 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" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

// Open workbook (update path as needed)
IWorkbook workbook = application.Workbooks.Open("PivotTable.xlsx");

// Get the first pivot table
IPivotTable pivotTable = workbook.Worksheets[0].PivotTables[0];

// Ensure layout is calculated
pivotTable.Layout();

// Read EndLocation from the implementation type
IRange endRange = (pivotTable as Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation;
int lastColumn = endRange.LastColumn;

// Use lastColumn as needed (e.g., log)
Console.WriteLine("PivotTable last column: " + lastColumn);
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

// Open workbook (update path as needed)
IWorkbook workbook = application.Workbooks.Open("PivotTable.xlsx");

// Get the first pivot table
IPivotTable pivotTable = workbook.Worksheets[0].PivotTables[0];

// Ensure layout is calculated
pivotTable.Layout();

// Read EndLocation from the implementation type
IRange endRange = (pivotTable as Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation;
int lastColumn = endRange.LastColumn;

// Use lastColumn as needed (e.g., log)
Console.WriteLine("PivotTable last column: " + lastColumn);
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Using excelEngine As New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx

' Open workbook (update path as needed)
Dim workbook As IWorkbook = application.Workbooks.Open("PivotTable.xlsx")

Dim pivotTable As IPivotTable = workbook.Worksheets(0).PivotTables(0)

' Calculate layout
pivotTable.Layout()

' Read EndLocation from implementation and get last column
Dim endRange As IRange = DirectCast(pivotTable, Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation
Dim lastColumn As Integer = endRange.LastColumn

Console.WriteLine("PivotTable last column: " & lastColumn)
End Using
{% endhighlight %}
{% endtabs %}

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).