需要帮助。我正在努力使用具有数据透视表的EPPlus在Exported excel中显示行字段和列字段。我已经尽力显示它了,但是没有用。我可以在数据透视表中看到的唯一一件事是数据计数。即使我在代码中添加了行字段,也没有列字段。
这里是我的代码。
var source = ws.Cells[startingrow, startingcol].LoadFromDataTable(dtData, true);
var range = source;
var rawrange = ws.Cells[ws.Dimension.Address];
//Pivot Sheet
var pvtsheet = wb.Worksheets.Add(report.PV_SheetName);
//Sheet Header
pvtsheet.Cells["A1"].Value = report.PV_SheetName;
pvtsheet.Cells["A2"].Value = "For the period: " + filter.DateCreated;
//Pivot Table Creation
var pt = pvtsheet.PivotTables.Add(pvtsheet.Cells["A5"], range, report.PV_SheetName);
pt.ShowHeaders = true;
//Row Labels
pt.RowFields.Add(pt.Fields[report.PV_RowLabel]); //value = "Problem"
pt.RowHeaderCaption = report.PV_RowLabel;
//Column Labels
pt.ColumnFields.Add(pt.Fields[report.PV_ColumnLabel]); //value = "Date Created"
pt.ColumnGrandTotals = true;
pt.GrandTotalCaption = "Total";
pt.DataOnRows = false;
pt.TableStyle = TableStyles.Dark1;
var datafield = pt.DataFields.Add(pt.Fields["Problem"]);
datafield.Function = OfficeOpenXml.Table.PivotTable.DataFieldFunctions.Count;
下面是我导出的Excel中的图片链接。