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

Corrupted pivot tables #1335

Open
2 of 3 tasks
Codendaal1120 opened this issue Jan 18, 2020 · 0 comments
Open
2 of 3 tasks

Corrupted pivot tables #1335

Codendaal1120 opened this issue Jan 18, 2020 · 0 comments

Comments

@Codendaal1120
Copy link

Codendaal1120 commented Jan 18, 2020

Read and complete the full issue template

Do you want to request a feature or report a bug?

  • Bug
  • Feature

If you are logging a possible bug or feature request, please test with the latest development build first.

Version of ClosedXML

Starting from 0.93

What is the current behavior?

When pre created pivot table sources, the file becomes corrupt and excel removes the pivot tables completely. This still works in v0.92.1. When opening the file, there is an error 👍

Removed Feature: PivotTable report from /xl/pivotCache/pivotCacheDefinition1.xml part (PivotTable cache)

Reproducibility

This is an important section. Read it carefully. Failure to do so will cause a 'RTFM' comment.

Code to reproduce problem:

I am using an excel sheet with pivot tables referencing sheets with tables, using ClosedXML I want to populate the source tables with data and update the pivot. The code is very simple

using (var workbook = new XLWorkbook(fileTemplate, XLEventTracking.Enabled))
{
    var metricsSheet = workbook.Worksheet("Metrics");
    var metricTable = metricsSheet.Tables.First();
    //metricTable.ReplaceData(metricsArray);
    metricTable.AppendData(metricsArray);
    metricsSheet.Columns().AdjustToContents();
    var metricsRange = metricTable.AsRange();

    //var outputsSheet = workbook.Worksheet("Output");
    //var outputTable = outputsSheet.Tables.First();
    //outputTable.AppendData(assignments);
    //outputsSheet.Columns().AdjustToContents();

    //foreach (var ws in workbook.Worksheets)
    //{
    //    if (ws.PivotTables == null || !ws.PivotTables.Any()) continue;

    //    var pivot = ws.PivotTables.First();
    //    pivot.SourceRange = metricsRange;
    //}

    Stream fs = new MemoryStream();
    workbook.SaveAs(fs);
    fs.Position = 0;
    return await Task.FromResult(fs);
}

auto_pivot_pre_open.xlsx

  • I attached a sample spreadsheet. (You can drag files on to this issue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant