I am using the Aspose Cells control in the attached example VS2010 project.
I have 2 sheets, the first being a data sheet and the second a pivot table of the data
In code, I am replacing the data in the data sheet and refreshing the pivot table to show the new data.
However when i do this, if I have a filter on the data in the pivot table sheet (in the template file there is a filter in PivotSheet Column B set to only show Pheonix items), this is lost when the newfile is created.
Is there a way to clear the data rows in the datasheet and refresh the pivot table but leave any filters that have been applied? I can do this in Excel but not in code?
Thanks
Martin
The issue is that our customers will be providing the template.xlsx file themselves, so i cannot guarantee that the template file is set to refresh the data.
However it seems it is the RefreshData() method that is clearing the filters.
If I do this:
if (!pivotTableItem.RefreshDataOnOpeningFile)
{
TryRefreshData(pivotTableItem);
}
TryCalculateData(pivotTableItem);
pivotTableItem.CalculateRange();
the filters remain in place. It would be a workaround, but ideally we would want the filters to not be cleared at all, whether by Aspose Cells or by Excel.
Regards
Martin
Hi,
I think you may try to use the workaround (skip the line(s) of code regarding RefreshData() method) for now with your Aspose.Cells version, it would work fine. In case you find any issue, do let us know with details and samples, we will check it soon.
Thank you.
Hi
Could you please advise if your solution is correct?
i.e. If the Excel file is set to update data on opening, does this mean I do not have to set RefreshData(), CalculateData() or CalculateRange() in code? I am not sure what these methods actually do and the help doc doesn’t explain it
Regards
Martin
Hi,
Well, your understanding is correct. Also, you may set MS Excel to refresh/update Pivot table programmatically on opening the file into it, you may simply (only) try to use PivotTable.RefreshDataOnOpeningFile to set it to true.
Hope, this helps a bit.
Thank you.