Foxtable(狐表)用户栏目专家坐堂 → [求助]


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

主题:[求助]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/7/18 11:14:00 [显示全部帖子]


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/7/18 12:39:00 [显示全部帖子]

mark 多层表头

 

Dim dt As Table = Tables("表C")
Dim nms() As String = {"第一列_aa", "第一列_bb", "第一列_cc","第三列", "第四列_a_b", "第四列_a_c"} '要导出的列名
Dim caps() As String = {"第一列_aa", "第一列_bb", "第一列_cc", "第三列","第四列_a_b","第四列_a_c"} '对应的列标题
Dim hlvl As Integer = 3
Dim szs() As Integer = {100,100,80} '对应的列宽
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim jz As xls.style = book.NewStyle
jz.AlignHorz = XLS.AlignHorzEnum.Center
jz.AlignVert = XLS.AlignVertEnum.Center
For c As Integer = 0 To nms.length -1
    Dim ary() As String = caps(c).split("_")
    For i As Integer = 0 To ary.length-1
        sheet(i, c).value = ary(i)
        sheet(i, c).Style = jz
    Next
Next
For i As Integer = 0 To hlvl-1
    Dim pi As Integer = 0
    For c As Integer = 0 To nms.length -2
        If sheet(i,c).text = sheet(i,c+1).text Then
            Dim flag As Boolean = True
            For k As Integer = i-1 To 0 Step -1
                If sheet(k,c).value <> sheet(k,c+1).value Then
                    flag = False
                End If
            Next
            If flag Then
                pi += 1
            Else
                pi = 0
            End If
        Else
            sheet.MergeCell(i, c-pi, 1, pi+1)
            pi = 0
        End If
    Next
    sheet.MergeCell(i, nms.length-pi-1, 1, pi+1)
Next

For c As Integer = 0 To nms.length -1
    Dim pi As Integer = 0
    For i As Integer = hlvl-1 To 0 Step -1
        If sheet(i, c).text = "" Then
            pi += 1
        Else
            sheet.MergeCell(i, c, pi+1, 1)
            Exit For
        End If
    Next 
next

For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
    For c As Integer = 0 To nms.length -1
        Sheet(r+hlvl, c).Value = dt.rows(r)(nms(c))
    Next
Next
book.save("d:\test.xls")


 回到顶部