Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共7 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

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

1楼
don 发表于: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编辑过]
2楼
狐狸爸爸 发表于:2008/11/19 12:46:00
哈哈,你比狐狸爸爸还精了,简直成狐狸精了。
精华!
3楼
程兴刚 发表于:2008/11/19 12:52:00
顶一个,学习,我该晕了!
4楼
czy 发表于:2008/11/19 12:58:00
顶下先,现在我对excel报表还不知所以然。
5楼
mr725 发表于:2008/11/19 13:02:00
'定額編號' don先生,你咋老是用繁体字呀,不会是马先生的子民吧?哈哈~  也许各有所好啦~
6楼
shxiaoya 发表于:2008/11/19 13:34:00
以下是引用mr725在2008-11-19 13:02:00的发言:
'定額編號' don先生,你咋老是用繁体字呀,不会是马先生的子民吧?哈哈~  也许各有所好啦~

人家那里不认简体

7楼
don 发表于:2008/11/19 16:38:00

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

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

共7 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03125 s, 3 queries.