这是一个手工录制的数据透视表的宏,想通过delphi 代码来操作EXCEL 达到执行该宏的效果.请问该如何写呢?Sub Macro1()
' ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'832006'!R1C1:R99C14").CreatePivotTable TableDestination:="", TableName:= _
"数据透视表1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("数据透视表1").PivotFields("公司")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("代码")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("名称")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("类型")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("舱位编码")
.Orientation = xlColumnField
.Position = 2
End With
ActiveSheet.PivotTables("数据透视表1").AddDataField ActiveSheet.PivotTables("数据透视表1" _
).PivotFields("金额"), "求和项:金额", xlSum
ActiveSheet.PivotTables("数据透视表1").AddDataField ActiveSheet.PivotTables("数据透视表1" _
).PivotFields("费用"), "求和项:费用", xlSum
End Sub
' ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'832006'!R1C1:R99C14").CreatePivotTable TableDestination:="", TableName:= _
"数据透视表1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("数据透视表1").PivotFields("公司")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("代码")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("名称")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("类型")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("数据透视表1").PivotFields("舱位编码")
.Orientation = xlColumnField
.Position = 2
End With
ActiveSheet.PivotTables("数据透视表1").AddDataField ActiveSheet.PivotTables("数据透视表1" _
).PivotFields("金额"), "求和项:金额", xlSum
ActiveSheet.PivotTables("数据透视表1").AddDataField ActiveSheet.PivotTables("数据透视表1" _
).PivotFields("费用"), "求和项:费用", xlSum
End Sub
解决方案 »
- delphi2005
- 求教高手 - 怎么模拟硬件的鼠标和键盘操作
- 调用FExcel.Cells时,怎么让生成的EXCLE文件自动宽度?
- 快来救命啊!神龙卡OSD的问题,帮帮忙啊
- 关于VB
- 这种切换页面的功能是如何实现的呢???(分少,见笑了,re者都有分!)
- 如何在自定义函数的单元文件中添加USES后就错了?
- 挥泪求救,如何实现图像边缘的抓取,UP者每人一分。
- 如何在导excel的时候设置每个column的宽度,以及cell的颜色属性?
- 程序运行时,如何控制TDBChart?
- delphi 操作网页onclick按钮
- TDBChart的DataSource用Summary时,Group by遇NULL会有问题?
http://www.delphibbs.com/keylife/iblog_show.asp?xid=27039