Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Pivot tables ClosedXML

Tags:

c#

closedxml

Using latest Closed XML (0.76) on Net 4.5.1

Created a Worksheet with a table by:

 DataTable Table = ...

 var DataWorkSheet = Workbook.Worksheets.Any(x => x.Name == "Data") ?
   Workbook
     .Worksheets
     .First(x => x.Name == "Data") :
   Workbook
     .Worksheets
     .Add("Data");

 int Start = ... // calculate cell start

 var Source = DataWorkSheet
   .Cell(Start, 1)
   .InsertTable(Table, Name, true);

 var Range = Source.DataRange;

This is done inside a loop (i.e. multiple tables in the "Data" sheet). A problem arises where the generated Excel document can't be opened if multiple pivot tables are created in a separate sheet.

 var PivotWorkSheet = Workbook
   .Worksheets
   .Add(Name);

 var Pivot = PivotWorkSheet
   .PivotTables
   .AddNew(Name, PivotWorkSheet.Cell(1, 1), DataRange);

Any ideas why and how to debug?

like image 305
Matthew Campbell Avatar asked Aug 24 '15 13:08

Matthew Campbell


People also ask

Does ClosedXML require Excel?

It is a . NET-library for report generation Microsoft Excel without requiring Excel to be installed on the machine that's running the code. With ClosedXML.

What is ClosedXML Excel?

ClosedXML is a . NET library for reading, manipulating and writing Excel 2007+ (. xlsx, . xlsm) files.

Is ClosedXML open source?

ClosedXML is an open source library created based on OpenXmlSdk. It's more user friendly. ClosedXML is a . NET library for reading, manipulating and writing Excel 2007+ (.


1 Answers

This is the same issue as in ClosedXML - Creating multiple pivot tables.

For the record, it's caused by ClosedXML bug which requires source code modification as in my answer of the linked question.

like image 184
Ivan Stoev Avatar answered Sep 23 '22 21:09

Ivan Stoev