Dim dt As Table = Tables("峰和设计部_table1")
Dim nms() As String = {"接单日期","量房时间","市场部","设计师","操作性","客户姓名","联系电话","小区地址","楼号","区域","面积","平面定金","立面定金金额","预收设计费","当月预签","预签时间","户型","设计部客户操作备注"} \'要导出的列名
Dim caps() As String = {"接单日期","量房时间","市场部","设计师","操作性","客户姓名","联系电话","小区地址","楼号","区域","面积","平面定金","立面定金金额","预收设计费","当月预签","预签时间","户型","设计部客户操作备注"} \'对应的列标题
Dim szs() As Integer = {90,90,70,70,70,80,100,90,80,70,50,80,80,85,80,90,40,120} \'对应的列宽
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"
For c As Integer = 0 To nms.length -1
Sheet(0, c).Value = caps(c) \'指定列标题
Sheet.Cols(c).Width = szs(c) \'指定列宽
If dt.Cols(nms(c)).IsDate Then \'如果是日期列
Sheet.Cols(c).Style = st \'设置显示格式
End If
Next
For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
For c As Integer = 0 To nms.length -1
Sheet(r +1, c).Value = dt.rows(r)(nms(c))
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