Dim tb As Table = CurrentTable ' Tables("往来款项台帐_Table1")
Dim hdr As Integer = tb.HeaderRows '获得表头的层数
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
tb.CreateSheetHeader(Sheet) '生成表头
''=======定义导出Excel表新样式===========
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.WordWrap = True '自动换行
Style.AlignVert = XLS.AlignVertEnum.Center '垂直居中
Style.Font = New Font("宋书", 9) '字体大小为9磅
Dim st As XLS.Style = Book.NewStyle() '日期列的显示格式
st.Format = "yyyy-MM-dd"
For cn As Integer = 0 To tb.Cols.Count - 1
If tb.Cols(cn).Visible Then
For r As Integer = 0 To tb.Rows.Count - 1 + hdr
sheet(r,cn).Style = Style '定义单元格线颜色
Next
For r As Integer = 0 To tb.Rows.Count - 1
If tb.Cols(cn).IsDate Then '如果是日期列
Sheet(r + hdr,cn).Style = st
End If
sheet(r + hdr,cn).Value = iif(tb(r,cn)=Nothing, "", tb(r,cn))
Next
End If
Next
Sheet.Rows.Insert(0)
sheet(0,0).Value = tb.DataTable.Name
sheet.MergeCell(0,0,1,CurrentTable.Cols.count)
st = Book.NewStyle() '日期列的显示格式
st.Font = new font("宋体", 20)
st.AlignHorz = XLS.AlignHorzEnum.Center
sheet(0,0).style = st
book.save("d:\test.xls")
Dim proc As new Process
proc.file = "d:\test.xls"
proc.start