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 @@ -6493,6 +6493,9 @@
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-Excel">How to retrieve the first cell in the used range in Excel?</a>
</li>
<li>
                     <a href="/document-processing/excel/excel-library/net/faqs/how-to-freeze-pivot-table-header-in-excel-workbook">How to freeze pivot table header in Excel workbook?</a>
                   </li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/does-xlsio-support-changing-the-colors-of-built-in-icon-sets">Does XlsIO support changing the colors of built-in icon sets?</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: How to freeze pivot table header in Excel workbook? | Syncfusion
description: Code example to freeze the header row/column of a PivotTable using Syncfusion .NET Excel library (XlsIO).
platform: document-processing
control: XlsIO
documentation: UG
---

# How to freeze pivot table header in Excel workbook?

The following code examples demonstrate freezing the header row and column of a PivotTable 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/Freeze%20Pivot%20Table%20Header/.NET/FreezePivotTableHeader/FreezePivotTableHeader/Program.cs,180" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));

//Freeze row and column
IWorksheet freezeSheet = workbook.Worksheets[1];
IRange range = freezeSheet.PivotTables[0].Location;
freezeSheet[range.Row + 1, range.Column + 1].FreezePanes();

//Save the workbook
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
}
{% endhighlight %}

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

//Freeze row and column (use correct worksheet index or name)
IWorksheet freezeSheet = workbook.Worksheets[1];
IRange range = freezeSheet.PivotTables[0].Location;
freezeSheet[range.Row + 1, range.Column + 1].FreezePanes();

//Save the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

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

'Freeze row and column (use correct worksheet index or name)
Dim freezeSheet As IWorksheet = workbook.Worksheets(1)
Dim range As IRange = freezeSheet.PivotTables(0).Location
freezeSheet(range.Row + 1, range.Column + 1).FreezePanes()

'Save the workbook
workbook.SaveAs("Output.xlsx")
End Using
{% endhighlight %}
{% endtabs %}

A complete working example in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Freeze%20Pivot%20Table%20Header/.NET/FreezePivotTableHeader">this GitHub page</a>.