Skip to content

Commit a206751

Browse files
989073-EndColumnPivotTable
1 parent c217036 commit a206751

1 file changed

Lines changed: 81 additions & 1 deletion

File tree

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

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,84 @@ 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).
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+
Imports System
394+
Imports Syncfusion.XlsIO
395+
396+
Using excelEngine As New ExcelEngine()
397+
Dim application As IApplication = excelEngine.Excel
398+
application.DefaultVersion = ExcelVersion.Xlsx
399+
400+
' Open workbook (update path as needed)
401+
Dim workbook As IWorkbook = application.Workbooks.Open("PivotTable.xlsx")
402+
403+
Dim pivotTable As IPivotTable = workbook.Worksheets(0).PivotTables(0)
404+
405+
' Calculate layout
406+
pivotTable.Layout()
407+
408+
' Read EndLocation from implementation and get last column
409+
Dim endRange As IRange = DirectCast(pivotTable, Syncfusion.XlsIO.Implementation.PivotTables.PivotTableImpl).EndLocation
410+
Dim lastColumn As Integer = endRange.LastColumn
411+
412+
Console.WriteLine("PivotTable last column: " & lastColumn)
413+
End Using
414+
{% endhighlight %}
415+
{% endtabs %}
416+
417+
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).

0 commit comments

Comments
 (0)