Skip to content

Commit ced0412

Browse files
991141-How to remove the source worksheet that contains data for pivot table
1 parent 07b2936 commit ced0412

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

Document-Processing-toc.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5848,6 +5848,9 @@
58485848
<li>
58495849
<a href="/document-processing/excel/excel-library/net/faqs/does-xlsio-support-auto-correcting formulas">Does XlsIO support auto-correcting formulas?</a>
58505850
</li>
5851+
<li>
5852+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-resolve-the-can't-open-Pivottable-source-file-error">How to resolve the “Can't open Pivottable source file” error?</a>
5853+
</li>
58515854
</ul>
58525855
</li>
58535856
</ul>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: Fix “Can't open PivotTable source file” error in XlsIO | Syncfusion
3+
description: This page explains how to resolve the "Can't open Pivottable source file" error using Syncfusion .NET Excel library (XlsIO).
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to resolve the “Can't open Pivottable source file” error?
10+
11+
Deleting the source worksheet and refreshing the PivotTable may work in the current session, but reopening the saved workbook and refreshing can trigger this error. If “Refresh data when opening the file” is enabled, Excel will not disable it automatically. This is Microsoft Excel behavior, and XlsIO follows the same behavior.
12+
13+
**Recommendations:**
14+
15+
If you need to remove the worksheet that contains the PivotTable’s source data, hide the worksheet instead of deleting it.
16+
If the source worksheet no longer exists, disable IsRefreshOnLoad before saving the workbook.
17+
18+
The following code illustrate how to disable the IsRefreshOnLoad property.
19+
20+
{% tabs %}
21+
{% highlight c# tabtitle="C# [Cross-platform]" %}
22+
using (ExcelEngine excelEngine = new ExcelEngine())
23+
{
24+
IApplication application = excelEngine.Excel;
25+
application.DefaultVersion = ExcelVersion.Xlsx;
26+
IWorkbook workbook = application.Workbooks.Open("Data/Sample.xlsx");
27+
IWorksheet pivotSheet = workbook.Worksheets[0];
28+
29+
IPivotTable pivotTable = workbook.Worksheets[1].PivotTables[0];
30+
PivotTableImpl pivotTableImpl = pivotTable as PivotTableImpl;
31+
32+
//Disable the refreshing option
33+
pivotTableImpl.Cache.IsRefreshOnLoad = false;
34+
35+
#region Save
36+
//Saving the workbook
37+
workbook.SaveAs("Output/PivotTable.xlsx");
38+
#endregion
39+
}
40+
{% endhighlight %}
41+
42+
{% highlight c# tabtitle="C# [Windows-specific]" %}
43+
using (ExcelEngine excelEngine = new ExcelEngine())
44+
{
45+
IApplication application = excelEngine.Excel;
46+
application.DefaultVersion = ExcelVersion.Xlsx;
47+
IWorkbook workbook = application.Workbooks.Open("Data/Sample.xlsx");
48+
IWorksheet pivotSheet = workbook.Worksheets[0];
49+
50+
IPivotTable pivotTable = workbook.Worksheets[1].PivotTables[0];
51+
PivotTableImpl pivotTableImpl = pivotTable as PivotTableImpl;
52+
53+
//Disable the refreshing option
54+
pivotTableImpl.Cache.IsRefreshOnLoad = false;
55+
56+
#region Save
57+
//Saving the workbook
58+
workbook.SaveAs("Output/PivotTable.xlsx");
59+
#endregion
60+
}
61+
{% endhighlight %}
62+
63+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
64+
Using excelEngine As New ExcelEngine()
65+
Dim application As IApplication = excelEngine.Excel
66+
application.DefaultVersion = ExcelVersion.Xlsx
67+
68+
Dim workbook As IWorkbook = application.Workbooks.Open("../../Data/Sample.xlsx")
69+
Dim pivotSheet As IWorksheet = workbook.Worksheets(0)
70+
Dim pivotTable As IPivotTable = workbook.Worksheets(1).PivotTables(0)
71+
Dim pivotTableImpl As PivotTableImpl = TryCast(pivotTable, PivotTableImpl)
72+
73+
' Disable the refreshing option
74+
pivotTableImpl.Cache.IsRefreshOnLoad = False
75+
76+
' Save the workbook
77+
workbook.SaveAs("../../Output/PivotTable.xlsx")
78+
End Using
79+
{% endhighlight %}
80+
{% endtabs %}
81+
82+
83+
The following code shows how to hide Excel worksheet.
84+
85+
{% tabs %}
86+
{% highlight c# tabtitle="C# [Cross-platform]" %}
87+
//Hide the worksheet
88+
worksheet.Visibility = WorksheetVisibility.Hidden;
89+
{% endhighlight %}
90+
91+
{% highlight c# tabtitle="C# [Windows-specific]" %}
92+
//Hide the worksheet
93+
worksheet.Visibility = WorksheetVisibility.Hidden;
94+
{% endhighlight %}
95+
96+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
97+
'Hide the worksheet
98+
worksheet.Visibility = WorksheetVisibility.Hidden
99+
{% endhighlight %}
100+
{% endtabs %}
101+
102+
## See Also
103+
104+
* [Hide Excel Worksheets](https://help.syncfusion.com/document-processing/excel/excel-library/net/migrate-from-office-automation-to-syncfusion-xlsio/hide-excel-worksheets)
105+
* [Working with Pivot Tables](https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-pivot-tables)

0 commit comments

Comments
 (0)