tab 1
此 demo 展示如何创建 excel 数据透视表。
如果这不是您想要的 demo,您可以通过填写表格获取免费定制 demo。
如您有与我们产品相关的其他技术问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。;销售相关的问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。。
tab 2
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
using system.data;
using spire.xls;
namespace demoonlinecode
{
class createpivottableinexcel
{
public void democreatepivottableinexcel(string filepath,string resultfilepath)
{
workbook workbook = new workbook();
workbook = createpivottable(filepath);
workbook.savetofile(resultfilepath);
}
public workbook createpivottable(string filepath)
{
workbook workbook = new workbook();
workbook.loadfromfile(filepath,excelversion.version2007);
worksheet sheet = workbook.worksheets[0];
sheet.name = "data source";
worksheet sheet2 = workbook.createemptysheet();
sheet2.name = "pivot table";
cellrange datarange = sheet.range["a1:g17"];
pivotcache cache = workbook.pivotcaches.add(datarange);
pivottable pt = sheet2.pivottables.add("pivot table", sheet.range["a1"], cache);
var r1 = pt.pivotfields["vendor no"];
r1.axis = axistypes.row;
pt.options.rowheadercaption = "vendor no";
var r2 = pt.pivotfields["name"];
r2.axis = axistypes.row;
pt.datafields.add(pt.pivotfields["area"], "average of area", subtotaltypes.average);
pt.datafields.add(pt.pivotfields["sales"], "sum of sales", subtotaltypes.sum);
pt.datafields.add(pt.pivotfields["onhand"], "max of onhand", subtotaltypes.max);
pt.datafields.add(pt.pivotfields["onorder"], "min of onorder", subtotaltypes.min);
pt.builtinstyle = pivotbuiltinstyles.pivotstylemedium12;
workbook.worksheets[1].remove();
sheet = workbook.worksheets[1];
sheet.columns[0].autofitcolumns();
sheet.columns[0].autofitrows();
sheet.allocatedrange.autofitcolumns();
sheet.allocatedrange.autofitrows();
return workbook;
}
}
}
tab 3
imports system.collections.generic
imports system.linq
imports system.text
imports system.threading.tasks
imports system.data
imports spire.xls
namespace demoonlinecode
class createpivottableinexcel
public sub democreatepivottableinexcel(filepath as string, resultfilepath as string)
dim workbook as new workbook()
workbook = createpivottable(filepath)
workbook.savetofile(resultfilepath)
end sub
public function createpivottable(filepath as string) as workbook
dim workbook as new workbook()
workbook.loadfromfile(filepath, excelversion.version2007)
dim sheet as worksheet = workbook.worksheets(0)
sheet.name = "data source"
dim sheet2 as worksheet = workbook.createemptysheet()
sheet2.name = "pivot table"
dim datarange as cellrange = sheet.range("a1:g17")
dim cache as pivotcache = workbook.pivotcaches.add(datarange)
dim pt as pivottable = sheet2.pivottables.add("pivot table", sheet.range("a1"), cache)
dim r1 = pt.pivotfields("vendor no")
r1.axis = axistypes.row
pt.options.rowheadercaption = "vendor no"
dim r2 = pt.pivotfields("name")
r2.axis = axistypes.row
pt.datafields.add(pt.pivotfields("area"), "average of area", subtotaltypes.average)
pt.datafields.add(pt.pivotfields("sales"), "sum of sales", subtotaltypes.sum)
pt.datafields.add(pt.pivotfields("onhand"), "max of onhand", subtotaltypes.max)
pt.datafields.add(pt.pivotfields("onorder"), "min of onorder", subtotaltypes.min)
pt.builtinstyle = pivotbuiltinstyles.pivotstylemedium12
workbook.worksheets(1).remove()
sheet = workbook.worksheets(1)
sheet.columns(0).autofitcolumns()
sheet.columns(0).autofitrows()
sheet.allocatedrange.autofitcolumns()
sheet.allocatedrange.autofitrows()
return workbook
end function
end class
end namespace