Dim dt As Table = Tables("表A")
Dim hdr As Integer = dt.HeaderRows
Dim cnt As Integer
Dim Book As New XLS.Book() '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim Style As XLS.Style = Book.NewStyle() '定义新样式
Dim St1 As xls.style = book.newstyle
Dim St2 As xls.style = book.newstyle
dt.CreateSheetHeader(Sheet,1)
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.Format = "yyyy-MM-dd"
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
Sheet(0,2).Value = "滨湖热力厂节能空间管理"
Sheet(0,9).Value = "打印日期:" & Format(Date.Today, "yyyy年MM月dd日")
St1.FontBold = True
Sheet(0,2).Style = St1
For r As Integer = 1 To 6
For c As Integer =1 To 9
If c=1 Then
Sheet(r,c).Style = St2
Else
Sheet(r,c).Style = Style
End If
Next
Next
For c As Integer = 0 To dt.Cols.Count - 1
If dt.Cols(c).Visible Then
For r As Integer = 0 To dt.Rows.Count - 1
sheet(r + hdr+1,cnt).value = dt(r,c)
Next
cnt = cnt + 1
End If
Next
Sheet.Cols.RemoveAt(0)
'Book.Build()
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Book.Save(dlg.FileName)
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If