Skip to content

Commit 978be03

Browse files
authored
Merge pull request #1856 from syncfusion-content/991141-Pivottable
991141- How to resolve the “Can't open Pivottable source file” error?
2 parents eff6956 + e1681da commit 978be03

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
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 Pivot table 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)