以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]Excel导出问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=143237) |
-- 作者:abc2363360 -- 发布时间:2019/11/18 14:36:00 -- [求助]Excel导出问题 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 如何才能把这个没用的数据在导出前删除?
|
-- 作者:有点蓝 -- 发布时间:2019/11/18 14:49:00 -- For r As Integer = 0 To dt.DataRows.Count - 1 For c As Integer = 0 To nms.Count -1 if dt.DataRows(r).isnull(nms(c)) = false Sheet(r +1, c).Value = dt.DataRows(r)(nms(c)) end if Next Next
|
-- 作者:abc2363360 -- 发布时间:2019/11/19 9:19:00 -- 谢谢,代码ok |