类似下面的代码:(在“演示样例”中的“高级报表”中的“多种交叉报表”中的计算之后的脚本)
复制内容到剪贴板
代码:
ChinaExcel.SetCanRefresh false
ChinaExcel.GetCellCombiNationWeb 2,4,StartCombiRow1,StartCombiCol1,nCombiRows1,nCombiCols1
ChinaExcel.InsertOnlyFormatCols StartCombiCol1+nCombiCols1,1,nCombiCols1,nCombiCols1
ChinaExcel.SetCellVal 2,StartCombiCol1+nCombiCols1+1,"体育课考试"
ChinaExcel.SetCellVal 3,StartCombiCol1+nCombiCols1+1,"合计"
for row=4 to ChinaExcel.GetMaxrow
sum=0
for col=StartCombiCol1 to StartCombiCol1+nCombiCols1
if ChinaExcel.GetCellValue(2,col) = ChinaExcel.GetCellValue(2,col+1) then
ChinaExcel.CombiNation 2,2,StartCombiCol1,col+1
if ChinaExcel.GetCellValue(row,col) <> "" then
sum = sum + ChinaExcel.GetCellValue(row,col)
end if
end if
next
ChinaExcel.SetCellVal row,StartCombiCol1+nCombiCols1+1,sum
next
ChinaExcel.GetCellCombiNationWeb 2,StartCombiCol1+nCombiCols1+2,StartCombiRow2,StartCombiCol2,nCombiRows2,nCombiCols2
ChinaExcel.InsertOnlyFormatCols StartCombiCol2+nCombiCols2,1,nCombiCols2,nCombiCols2
ChinaExcel.SetCellVal 2,StartCombiCol2+nCombiCols2+1,"文化课考试"
ChinaExcel.SetCellVal 3,StartCombiCol2+nCombiCols2+1,"合计"
for row=4 to ChinaExcel.GetMaxrow
sum=0
for col=StartCombiCol2 to StartCombiCol2+nCombiCols2
if ChinaExcel.GetCellValue(2,col) = ChinaExcel.GetCellValue(2,col+1) then
ChinaExcel.CombiNation 2,2,StartCombiCol2,col+1
if ChinaExcel.GetCellValue(row,col) <> "" then
sum = sum + ChinaExcel.GetCellValue(row,col)
end if
end if
next
ChinaExcel.SetCellVal row,StartCombiCol2+nCombiCols2+1,sum
next
ChinaExcel.SetCanRefresh true
ChinaExcel.Refresh