Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim st As XLS.Style = Book.NewStyle '日期列的显示格式
st.Format = "yyyy-MM-dd"
Dim t As Table = Tables("纳税人档案")
Dim c As Col
For i As Integer = 0 To t.Cols.Count -1
c = t.Cols(i)
Sheet(0, i).Value = c.Name '指定列标题
If c.IsDate Then '如果是日期列
Sheet.Cols(i).Style = st '设置显示格式
End If
Next
For r As Integer = 0 To t.Rows.Count - 1 '填入数据
For j As Integer = 0 To t.Cols.Count -1
c = t.Cols(j)
If c.IsBoolean Then
Sheet(r +1, j).Value = IIF(t.rows(r)(t.Cols(j).Name),"是","否")
Else
Sheet(r +1, j).Value =t.rows(r)(t.Cols(j).Name)
End If
Next
Next
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