首页 > 代码库 > Epplus做Excel的数据透视

Epplus做Excel的数据透视

 1 //表格的范围需要自己定义
 2 var epplus = new ExcelPackage();
 3 var sheet = epplus.Workbook.Worksheets.Add("Sheet1");
 4 var dataRange = sheet.Cells[1, 37, row, 39];
 5 var wsPivot = epplus.Workbook.Worksheets.Add("数据透视表");
 6 var pt = wsPivot.PivotTables.Add(wsPivot.Cells["A1"], dataRange, "Name");
 7 pt.Compact = true;
 8 pt.CompactData = http://www.mamicode.com/true;
 9 pt.GrandTotalCaption = "Total amount";
10 pt.Fields[2].Sort = eSortType.Ascending; 11 pt.RowFields.Add(pt.Fields[2]); 12 pt.DataFields.Add(pt.Fields[0]); 13 pt.DataFields.Add(pt.Fields[1]); 14 pt.DataFields[0].Function = DataFieldFunctions.Sum; 15 pt.DataFields[1].Function = DataFieldFunctions.Sum; 16 pt.DataOnRows = false;

 

Epplus做Excel的数据透视