Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Existing Pivot Table loses filters/grouping after the xlsm file is saved #1701

Open
draedr opened this issue Nov 19, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@draedr
Copy link

draedr commented Nov 19, 2024

EPPlus usage

Noncommercial use

Environment

Windows

Epplus version

7.5.0

Spreadsheet application

Excel

Description

I have an Excel file that i use as template, which already contains a Pivot Table. This pivot table is grouped by years, quarter and month, and is the base for a chart.
After the ExcelPackage is saved, though, the filters/grouping disappear.
The only operation i did on the pivot was to change the CacheDefinition.SourceRange, but i also tried executing it without making any change to the pivot, and it still loses the filters.

Also, the file is an .xlsm that contains macro, but the macros don't interact with the pivot table or the table which uses as source.

@draedr draedr added the bug Something isn't working label Nov 19, 2024
@JanKallman
Copy link
Contributor

Can you attach the workbook and code to reproduce this issue?

@draedr
Copy link
Author

draedr commented Nov 22, 2024

Hi, yes, here is the workbook and the code.

Settimanale.zip

var OutputFile = $"C:\\Users\\user\\Desktop\\Out_{DateTime.Now.Millisecond}.xlsm";
using var template = File.OpenRead("Settimanale.xlsm");
MemoryStream ret = new MemoryStream();

using (var document = new ExcelPackage(ret, template))
{
    string sheetNameConfrontoRichieste22_23_24 = "confronto richieste 22-23-24";
    var sheetConfrontoRichieste22_23_24 = document.Workbook.Worksheets[sheetNameConfrontoRichieste22_23_24];

    int sheetConfrontoRichiesteSettingsStartRow = 3;

    var sheetConfrontoRichieste = document.Workbook.Worksheets["input confronto richieste"];

    document.Save();
    ret.Position = 0;
}

using (FileStream file = new FileStream(OutputFile, FileMode.Create, FileAccess.Write))
{
    ret.WriteTo(file);
}

@JanKallman
Copy link
Contributor

EPPlus will refresh the pivot table on save, so if there is no data in the source the items will disappear..
Looking at the sample attached it's not clear to me what the issue is. It contains several worksheets and pivot tables.
Can you provide an isolated sample that shows the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants