Dim cmd As New SQLCommand
cmd.C
Dim nms() As String = {"报障时间","区域","客户名称","业务类型","服务级别","故障处理过程","抢修部门","销障时间","工单状态"}
cmd.CommandText = "Select 报障时间,区域,客户名称,业务类型,服务级别,故障处理过程,抢修部门,销障时间,工单状态 Fro m {集客故障记录表} where 工单状态 = '新增' or (工单状态 = '销障'and convert(varchar(10),[业务确认时间],120) = convert(varchar(10),getdate(),120)) ORDER BY 报障时间 Desc"
Dim dt As DataTable = cmd.ExecuteReader()
Dim Book As New XLS.Book
Book.Sheets.Add("集客故障") '增加一个名为"集客故障"的工作表
Book.Sheets.Add("家客故障") '增加一个名为"家客故障"的工作表
Book.Sheets.Remove("Sheet1")
Dim Sheet As XLS.Sheet = Book.Sheets("集客故障")
Dim st As XLS.Style = Book.NewStyle '日期列的显示格式
st.Format = "yyyy-MM-dd hh:mm:ss"
For c As Integer = 0 To nms.Count -1
Sheet(0, c).Value = nms(c)
If dt.DataCols(nms(c)).IsDate Then '如果是日期列
Sheet.Cols(c).Style = st '设置显示格式
End If
Next
For r As Integer = 0 To dt.DataRows.Count - 1
For c As Integer = 0 To nms.Count -1
Sheet(r +1, c).Value = dt.DataRows(r)(nms(c))
Next
Next
Book.Save("C:\Users\GDTT\Desktop\test.xls") '保存excel
导出的excel表中,如果数据库日期时间列没内容,导出的表显示为1900/1/0 0:00:00 如何才能把这个没用的数据在导出前删除?
此主题相关图片如下:qq图片20191118115612.png