JanKallman / EPPlus

Create advanced Excel spreadsheets using .NET
3.76k stars 1.18k forks source link

How to refresh PivotTable cache #125

Open ajaygupta2000 opened 6 years ago

ajaygupta2000 commented 6 years ago

My workbook is having a pivot table which computes summary from one of my worksheets. I am adding new rows to this worksheet through EPPLUS and want to refresh the pivot table after that. But I could not find any way to refresh the pivot table through EPPlus. Is this feature existing in 4.5.0, if not do you have any plans to implement it.

Thanks, AG

gcoh commented 5 years ago

i have the same problem !

i tried this code , but i don't find the function to refresh the ### pivot

foreach (ExcelWorksheet wsl in p.Workbook.Worksheets) { wsl.Workbook.Calculate(); foreach (OfficeOpenXml.Table.PivotTable.ExcelPivotTable pivotTable in wsl.PivotTables) {

### pivotTable.?????

                                }
                            }
tienvd1994 commented 5 years ago

@JanKallman @gcoh @ajaygupta2000 I have same problem. How to to fix this problem?

haysuse commented 4 years ago

https://stackoverflow.com/a/39294261/61525

I couldn't find a way to achieve this using EPPlus.

However, you can enable the "Refresh the data when opening the file" property on the PivotTable manually before modifying the file, so that when you open the file using Excel, the content of the PivotTable will be calculated based on the modified data. You can find this property under the Data tab in the PivotTable options.

haysuse commented 4 years ago

Or Add this to ExcelPivotCacheDefinition.cs

public bool RefreshOnLoad
{
    get
    {
        return GetXmlNodeString("@refreshOnLoad") == "1";
    }
    set
    {
        SetXmlNodeString("@refreshOnLoad", value?"1":"0");
    }
}