Dim tbl As Table = CurrentTable
Dim hdr As Integer = tbl.HeaderRows '获得表头的层数
Dim cnt As Integer
Dim Book As New XLS.Book
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim Sty As xls.style = book.NewStyle
sty.AlignHorz = XLS.AlignHorzEnum.Center
Sty.BorderTop = XLS.LineStyleEnum.Thin
Sty.BorderBottom = XLS.LineStyleEnum.Thin
Sty.BorderLeft = XLS.LineStyleEnum.Thin
Sty.BorderRight = XLS.LineStyleEnum.Thin
Sty.BorderColorTop = Color.Red
Sty.BorderColorBottom = Color.Red
Sty.BorderColorLeft = Color.Red
Sty.BorderColorRight = Color.Red
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.Red
Style.BorderColorBottom = Color.Red
Style.BorderColorLeft = Color.Red
Style.BorderColorRight = Color.Red
tbl.CreateSheetHeader(Sheet) '生成表头
Dim c = 0
For Each c1 As Col In tbl.cols
If c1.visible=True
For i As Integer = 0 To hdr
sheet(i, c).style = sty
Next
c=c+1
End If
Next
For r As Integer = hdr To tbl.Rows.Count+hdr - 1 '填入数据
c =0
For Each c1 As Col In tbl.cols
If c1.visible=True
Sheet(r, c).style = style
Sheet(r, c).value = tbl(r-hdr,c1.Index)
c=c+1
End If
Next
Next
Book.Save("c:\reports\test.xls")
Dim Proc As New Process
Proc.File = "c:\reports\test.xls"
Proc.Start()