I am generating two worksheets, one for data and one for pivot table named 'worksheet1_data' and 'worksheet1' respectively in same workbook using ep plus. It seems good when I save for first time. Again I process this excel file (.xlsx) and added two new worksheets 'worksheet2_data' and 'worksheet2' in it and generated new pivot table with datasource from 'worksheet2_data'. When I open the file, pivot table in 'worksheet1' and 'worksheet2' both have datasource of 'worksheet1_data', even if I add more pivot tables, all have datasource of 'worksheet1_data'.
The code works fine while debugging but datasources change while opening excel sheet. Can any one suggest what could be the issue?
Below is my code:
ExcelWorksheet worksheetManagementARReportData = package.Workbook.Worksheets.Add(EndDate.ToString("MM-dd-yyyy") + "_Data");
ExcelWorksheet worksheetManagementARReport = package.Workbook.Worksheets.Add(EndDate.ToString("MM-dd-yyyy"));
var dataRange_ManagementARReport = worksheetManagementARReportData.Cells["A1"].LoadFromDataTable(dsGetManagementARReport.Tables[0], true);
var pivotTableManagementARReport = worksheetManagementARReport.PivotTables.Add(worksheetManagementARReport.Cells["A1"], dataRange_ManagementARReport, "PivotTable" + EndDate.ToString("MM_dd_yyyy") + "_ManagementARReport");
Tbl_AutomatedReport.PivotTable(rowfield, columnfield, pagefield, datafields, pivotTableManagementARReport);