Foxtable(狐表)用户栏目专家坐堂 → 合併Excel报表指定列相同單元格


  共有27006人关注过本帖树形打印复制链接

主题:合併Excel报表指定列相同單元格

帅哥哟,离线,有人找我吗?
don
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
合併Excel报表指定列相同單元格  发帖心情 Post By:2008/11/19 12:43:00 [显示全部帖子]

Excel報表現在可算比較完美了,唯一缺點就是沒有對指定列合併相同單元格功能,唯有自己想法解決,下面的代碼於模板,對第一,第二列的"序號"及"定額編號"合併相同單元格(沒有考慮跨頁合併)

Dim Ta As Table = Tables("材料分析")
Dim Tt1 As String = ProjectPath & "Attachments\"
Dim Tt2 As String = ProjectPath & "reports-:special:1:-

If Ta.Rows.Count > 0 Then
    Ta.Select(0,1,Ta.Rows.count-1,1)

        Dim Book As New XLS.Book(Tt1 & "詳細分析.xls") '打开模板
        Dim Sheet As XLS.Sheet = Book.Sheets(0)  
        Book.Build() '生成细节区

        Book.Save(Tt2 & "詳細分析.xls") 

        Dim i,n,sum As Integer
        Dim Book1 As New XLS.Book(Tt2 & "詳細分析.xls")
        Dim Sheet1 As XLS.Sheet = Book1.Sheets(0)
        Dim Ls,Ls1 As  String

        For i = 0 to Ta.Rows.count-1
              If Ls = nothing Then
                     Ls ="," & Ta.Rows(i)("序號")
                     Ls1 ="," & Ta.Rows(i)("定額編號")                       
               ElseIf Ls.IndexOf(Ta.Rows(i)("序號"))=-1 Then
                     Ls = Ls & "," & Ta.Rows(i)("序號")
               ElseIf Ls1.IndexOf(Ta.Rows(i)("定額編號"))=-1 Then
                     Ls1 = Ls1 & "," & Ta.Rows(i)("定額編號")
               End If
        Next


        For i = 1 to Ls.split(",").Length-1
            n = Ta.Compute("count(序號)","序號 = " & Ls.split(",")(i))
            sum = sum+n
            Sheet1.MergeCell(sum-n+3,0,n,1)
        Next

        sum = 0
        For i = 1 to Ls1.split(",").Length-1
            n = Ta.Compute("count(定額編號)","定額編號 = '" & Ls1.split(",")(i) & "'")
            sum = sum+n
            Sheet1.MergeCell(sum-n+3,1,n,1)
        Next
       
        Book1.Save(Tt2 & "詳細分析.xls")
        Dim Proc1 As New Process
        Proc1.File = Tt2 & "詳細分析.xls"
        Proc1.Start()
End If
Ta.Select(1,1,1,1)


此主题相关图片如下:hb.gif
按此在新窗口浏览图片
[此贴子已经被作者于2008-11-19 17:00:54编辑过]

[本帖被加为精华]
 回到顶部
帅哥哟,离线,有人找我吗?
don
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
  发帖心情 Post By:2008/11/19 16:38:00 [显示全部帖子]

还是来个实例吧!看材料分析表全部显示及按页筛选后,Excel报表合并列有何区别:

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:材料分析.rar


 回到顶部