Foxtable(狐表)用户栏目专家坐堂 → excel报表 怎么在生成复杂表头的前提上新增一行作标题 在新增一行 加单位 呢?


  共有4785人关注过本帖平板打印复制链接

主题:excel报表 怎么在生成复杂表头的前提上新增一行作标题 在新增一行 加单位 呢?

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
excel报表 怎么在生成复杂表头的前提上新增一行作标题 在新增一行 加单位 呢?  发帖心情 Post By:2021/5/15 16:16:00 [只看该作者]

excel报表  怎么在生成复杂表头的前提上新增一行作标题 在新增一行 加单位 呢?
下述红色代码没有发挥作用   麻烦老师们指导下!谢谢!

当前代码如下:
Dim tbl As Table = Tables("党史统计表")
Dim dt1 As Table = Tables("词典")
Dim hdr As Integer = tbl.HeaderRows '获得表头的层数
Dim cnt As Integer
Dim Book As New XLS.Book
Dim Sheet As XLS.Sheet = Book.Sheets(0)
tbl.CreateSheetHeader(Sheet) '生成表头

Dim Style As Xls.Style = Book.NewStyle '新建一个线框样式
Style.BorderTop = XLS.LineStyleEnum.Thin
Style.BorderBottom = XLS.LineStyleEnum.Thin
Style.BorderLeft = XLS.LineStyleEnum.Thin
Style.BorderRight = XLS.LineStyleEnum.Thin
Style.BorderColorTop = Color.Black
Style.BorderColorBottom = Color.Black
Style.BorderColorLeft = Color.Black
Style.BorderColorRight = Color.Black
Style.AlignHorz=XLS.AlignHorzEnum.Center
Style.AlignVert=XLS.AlignVertEnum.Center
Style.FontBold = True '字体加粗
Style.Font = New Font("仿宋", 12 , FontStyle.Bold)
Style.WordWrap=True
Dim St21 As Xls.Style = Book.NewStyle '新建一个时间格式化样式
st21.Font = New Font("仿宋", 20 , FontStyle.Bold)
St21.AlignHorz=XLS.AlignHorzEnum.Center
St21.AlignVert=XLS.AlignVertEnum.Center

Dim St2 As Xls.Style = Book.NewStyle '新建一个时间格式化样式
St2.Format = "yyyy-MM-dd"
St2.BorderTop = XLS.LineStyleEnum.Thin
St2.BorderBottom = XLS.LineStyleEnum.Thin
St2.BorderLeft = XLS.LineStyleEnum.Thin
St2.BorderRight = XLS.LineStyleEnum.Thin
St2.BorderColorTop = Color.Black
St2.BorderColorBottom = Color.Black
St2.BorderColorLeft = Color.Black
St2.BorderColorRight = Color.Black
St2.AlignHorz=XLS.AlignHorzEnum.Center
St2.AlignVert=XLS.AlignVertEnum.Center
St2.FontBold = True '字体加粗
St2.Font = New Font("仿宋", 12, FontStyle.Bold)
st2.WordWrap=True

For c As Integer = 0 To tbl.Cols.Count - 1
    Sheet.Cols(c).Width =80
    Sheet.Cols(13).Width =400
    Sheet.Cols(16).Width =200
    Sheet.Cols(17).Width =400
    Sheet.Cols(19).Width =200
    Sheet.Cols(20).Width =400
    Sheet.Cols(22).Width =400
    Sheet.Cols(26).Width =400
    Sheet.Cols(30).Width =200
    'Sheet(0, c).Value ="党史学习教育开展情况统计表"   
    'Sheet.MergeCell(0,0,1,c+1)
    'Sheet(1, 0).Value ="单位"    
    'Sheet.MergeCell(1,2,1,3)
    If tbl.Cols(c).Visible Then
        For r As Integer = 0 To tbl.Rows.Count - 1
            Sheet.Rows(0).Height = 40
            Sheet.Rows(1).Height = 40
            Sheet.Rows(r).Height = 30
            sheet(r + hdr+2,cnt).value = tbl(r,c)
        Next
        cnt = cnt + 1
    End If
Next
For r1 As Integer = 0 To dt1.Rows.Count - 1 '填入数据
    For c1 As Integer = 0 To tbl.Cols.Count-1
        Sheet(r1+2, 13).Value = dt1.rows(r1)(0)    
        Sheet(r1+2, 12).Value = r1+1  
    Next
Next
For r2 As Integer = 0 To Sheet.rows.count-1
Sheet.Rows(0).Height = 40
Sheet.Rows(1).Height = 60
Sheet.Rows(r2).Height = 30
'Sheet(0, 1).style=st21
    For c1 As Integer = 0 To tbl.Cols.Count-1
        If tbl.Cols(c1).IsDate
            Sheet(r2,c1).Style = St2
        Else
            Sheet(r2,c1).Style = Style
        End If
    Next
Next
Book.Save("c:\reports\test.xls")
Dim Proc As New Process
Proc.File = "c:\reports\test.xls"
Proc.Start()
实现效果如下:

图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2021/5/15 16:19:47编辑过]

 回到顶部
总数 34 1 2 3 4 下一页