Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Jul 24, 2023 10:43 am

Hello everyone,

I have an Excel file with a pivot table on the first sheet and the source data on a second sheet. I would like to use this Excel file as a template and automatically exchange the sheet with the source data.
This works so far without any problems.
Unfortunately, the source data range to which the pivot table refers does not update.
There were 100 records in the template. If I then overwrite the source data sheet with 120 records, the pivot table still only refers to the first 100 rows.
Is there a possibility to adjust the source data range afterwards?

Thank you and best regards
Varauccc

Varauccc
 
Posts: 1
Joined: Mon Jul 24, 2023 10:29 am

Tue Jul 25, 2023 2:16 am

Hi Varauccc,

Thank you for your inquiry.

You can utilize the method Spire.Xls.PivotTable.ChangeDataSource(Spire.Xls.Core.IXLSRange dataSource) to modify the data source of your pivot table. This method automatically recalculates the pivot table, eliminating the need to call the CalculateData() method separately.

To assist you further, please refer to the following example code:

Code: Select all
Workbook book = new Workbook();
book.LoadFromFile(inputFile);
Worksheet sheet = book.Worksheets[0];
CellRange Range = sheet.Range["A1:C15"];
Spire.Xls.PivotTable table = book.Worksheets[1].PivotTables[0] as Spire.Xls.PivotTable;
table.ChangeDataSource(Range);
table.Cache.IsRefreshOnLoad = false;
book.SaveToFile(outputFile, ExcelVersion.Version2010);
book.Dispose();


If you have any additional questions or require further assistance, please feel free to reach out to us. We are here to assist you.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Aug 16, 2023 7:52 pm

Note that so far when I attempted to update data in the data range of an existing pivot table, it did NOT work if using MarkerDesigner to insert the data into the source range. It got an index out of range error. I suspect the marker designer of attempting to update inside of the pivot table itself where the data cache has picked up on the &= markers.

DaMiller
 
Posts: 8
Joined: Thu Jan 12, 2023 9:12 pm

Thu Aug 17, 2023 5:41 am

DaMiller wrote:Note that so far when I attempted to update data in the data range of an existing pivot table, it did NOT work if using MarkerDesigner to insert the data into the source range. It got an index out of range error. I suspect the marker designer of attempting to update inside of the pivot table itself where the data cache has picked up on the &= markers.


Hi,

Thanks for your feedback.
Could you please share us with your test code and document? So that we can investigate further and work out a solution for you. You can share them with us via email(support@e-iceblue.com) or attach them here. Thanks for you assistance in advance.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS