发新话题
打印

在交叉报表中如何使用同一行中相邻相同内容的单元组合

在交叉报表中如何使用同一行中相邻相同内容的单元组合

在主从报表中可以使用“同一行中相邻相同内容的单元组合”这个选项,但是在交叉报表中却没有,请问怎么在交叉报表也使用这个功能呢?

TOP

可以在“计算之后的运行脚本”中设置,先判断相邻单元格内容是否相同,如果相同就用CombiNation组合。

TOP

二楼说的有道理,可以用这个方法来实现。

TOP

请问应该怎么写代码呢?我是个初学者,可否给个例子看看,谢谢了

TOP

类似下面的代码:(在“演示样例”中的“高级报表”中的“多种交叉报表”中的计算之后的脚本)
复制内容到剪贴板
代码:
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

TOP

发新话题
最近访问的版块