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 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("仿宋", 11 , 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 St211 As Xls.Style = Book.NewStyle '新建一个时间格式化样式
st211.Font = New Font("仿宋", 11 , FontStyle.Bold)
St211.AlignHorz=XLS.AlignHorzEnum.Left
St211.AlignVert=XLS.AlignVertEnum.Center
Dim St2111 As Xls.Style = Book.NewStyle '新建一个时间格式化样式
st2111.Font = New Font("仿宋", 30 , FontStyle.Bold)
St2111.AlignHorz=XLS.AlignHorzEnum.Center
St2111.AlignVert=XLS.AlignVertEnum.Center
Dim Sheet As XLS.Sheet = Book.Sheets(0)
sheet.Name="学习教育工作情况统计表"
tbl.CreateSheetHeader(Sheet) '生成表头
Sheet.Rows.Insert(0)
Sheet.Rows.Insert(0)
Sheet(0, 0).Value ="党史学习教育暨" & """牢记殷切嘱托 忠诚干净担当 喜迎建党百年""" & "专题教育工作开展情况统计表"
Sheet(0, 0).Style=st2111
Sheet.MergeCell(0,0,1,32)
Sheet(1, 0).Value ="单位:"
Sheet(1, 0).Style=st211
Sheet.MergeCell(1,1,1,3)
Sheet(1, 1).Value ="xxxx"
Sheet(1, 1).Style=st211
Sheet.MergeCell(1,1,1,5)
Sheet(1, 6).Value ="填报人:"
Sheet.MergeCell(1,6,1,2)
Sheet(1, 6).Style=st211
Sheet(1, 8).Value ="xxxx"
Sheet(1, 8).Style=st211
Sheet.MergeCell(1,8,1,3)
Sheet(1, 11).Value ="联系电话:"
Sheet.MergeCell(1,11,1,2)
Sheet(1, 11).Style=st211
Sheet(1, 13).Value ="xxxxx"
Sheet(1, 13).Style=st211
Sheet(1, 19).Value ="报表时间:"
Sheet(1, 19).Style=st211
Sheet(1, 20).Value =Format(Date.today, "yyyy年MM月dd日")
Sheet(1, 20).Style=st211
Sheet(1, 22).Value ="主要领导签字:"
Sheet(1, 22).Style=st211
Sheet.MergeCell(1,22,1,4)
Sheet.Rows(24).PageBreak = True '每页24行后强制换页
Sheet.Rows.Frozen = 4 '冻结表前面四行
'
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 =40
Next
Sheet.Cols(13).Width =150
Sheet.Cols(14).Width =90
Sheet.Cols(16).Width =120
Sheet.Cols(17).Width =150
Sheet.Cols(19).Width =120
Sheet.Cols(20).Width =150
Sheet.Cols(22).Width =150
Sheet.Cols(23).Width =90
Sheet.Cols(24).Width =80
Sheet.Cols(26).Width =120
Sheet.Cols(30).Width =120
For r11 As Integer = 0 To dt1.Rows.Count - 1 '填入数据
For c11 As Integer = 0 To tbl.Cols.Count-1
Sheet(r11+4, 13).Value = dt1.rows(r11)(0)
Sheet(r11+4, 12).Value = r11+1
Next
Next
For r2 As Integer = 0 To Sheet.rows.count-1
Sheet.Rows(0).Height = 80
Sheet.Rows(1).Height = 40
Sheet.Rows(2).Height = 40
Sheet.Rows(3).Height = 80
Sheet.Rows(r2).Height = 50
For c1 As Integer = 0 To tbl.Cols.Count-1
If tbl.Cols(c1).IsDate
Sheet(r2+2,c1).Style = St2
Else
Sheet(r2+2,c1).Style = Style
End If
Next
Next
'打印设置
With Sheet.PrintSetting
.AutoScale = True
.FitPagesAcross=1
.PaperKind = 8 '设为A3纸
.LandScape = True '横向打印
.MarginLeft = 20 '左右边距设为20毫米
.MarginRight = 20
.MarginTop = 15 '上下边距设为15毫米
.MarginBottom = 15
.Footer = "&R第&P页,总&N页"
End With
'保存表并打开文件
Book.Save("c:\reports\test.xls")
Dim Proc As New Process
Proc.File = "c:\reports\test.xls"
Proc.Start()