I have an EXCEL 2007 template workbook (Template.xlsx) with 3 named worksheets: pivot table (PVT), data sheet (DataFinal), notes (Notes). The Pivot table datasource has a pre-existing named range. That named range points to the DataFinal sheet. My ASPOSE code writes a datatable to the DataFinal worksheet and set the range and refreshes the data:
Worksheet pivotTableSheet = workbook.Worksheets.GetSheetByCodeName("Pvt"); PivotTable pivotTable = pivotTableSheet.PivotTables; Range range = dataFinalSheet.Cells.CreateRange(0, 0, dataFinalSheet.Cells.MaxDataRow + 1, dataFinalSheet.Cells.MaxColumn); range.Name = "MngfulDiffAnalysisDataSource"; pivotTable.RefreshData(); workbook.Save(filePath);
When I open the final output: Final.xlsx, I get the following errors which also removes the pivot table:
- <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error104520_04.xml</logFileName><summary>Errors were detected in file 'C:\Users\Pyousefi\Desktop\MngfulDiffAnalysis2011_5_16_2011.xlsx'</summary>- <removedParts summary="Following is a list of removed parts:"><removedPart>Removed Part: /xl/pivotTables/pivotTable2.xml part. (PivotTable view)</removedPart></removedParts>- <removedRecords summary="Following is a list of removed records:"><removedRecord>Removed Records: Workbook properties from /xl/workbook.xml part (Workbook)</removedRecord></removedRecords></recoveryLog>
I think that this has something to do with creating a range with the name of a pre-existing range.How would I modify the pre-existing named range if that is the case?