문제

We are using ClosedXML to generate .XLSX spreadsheets because it is small, nimble, and quick. It appears that all the pivot table classes and methods are there in the API, but there is no documentation or examples on how to go about (in the correct sequence) creating pivot tables. Our attempts at guessing have produced files that when opened, give an error about XML corruption, and Excel prompts you to delete the pivot table.

도움이 되었습니까?

해결책

I'm not sure at what version ClosedXML implemented Pivot Tables, but as of at least v0.70 they have been implemented. An example can be found in the ClosedXML Documentation. Below is an C# example I'm using in my own project.

IXLWorksheet xlPvSheet = xlBook.Worksheets.Add("Pivot");
IXLPivotTable xlPvTable = xlPvSheet.PivotTables.AddNew("PivotTable", xlPvSheet.Cell(1,1), xlForecastSheet.Range(1, 1, r, 11));
xlPvTable.RowLabels.Add("Box Type");
xlPvTable.RowLabels.Add("Box Color");
xlPvTable.ColumnLabels.Add("Request Date");
xlPvTable.Values.Add("Total Boxes");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top