以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 导出后台数据时,日期列为空时,所导出的EXCEL表中的对应单元格内容变成了1900 - 01 - 00。如何把这部分单元格变为空 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=187704) |
-- 作者:HANZHIGANG -- 发布时间:2023/8/5 15:43:00 -- 导出后台数据时,日期列为空时,所导出的EXCEL表中的对应单元格内容变成了1900 - 01 - 00。如何把这部分单元格变为空 如题 |
-- 作者:有点蓝 -- 发布时间:2023/8/5 17:14:00 -- 怎么导的? |
-- 作者:HANZHIGANG -- 发布时间:2023/8/5 17:23:00 -- If Tables(maintable.Name).Rows.Count = 0 Then MessageBox.Show("无可导出数据,请重新确认!", "提示") Else Dim cmd As New SQLCommand cmd.C Dim nms() As String = {"锁定", "返单公司", "支付", "结算", "部门", "结算单号", "调度单号", "车牌号", "驾驶员", "车辆类型", "调度动态", "台数", "下游金额", "下游调整", "下游考核", "预借现金", "预借油卡", "下游余款", "余款类型", "卡号", "结算备注", "调度备注", "承运单位", "结算员", "结算日期", "打印人", "打印日期", "打印次数"} If Filter > "" Then cmd.CommandText = "Se lect 锁定, 返单公司, 支付, 结算, 部门, 结算单号, 调度单号, 车牌号, 驾驶员, 车辆类型, 调度动态, 台数, 下游金额, 下游调整, 下游考核, 预借现金, 预借油卡, ISNULL(下游金额,0) + ISNULL(下游调整,0) - ISNULL(下游考核,0) - ISNULL(预借现金,0) - ISNULL(预借油卡,0) As 下游余款, 余款类型, 卡号, 结算备注, 调度备注, 承运单位, 结算员, 结算日期, 打印人, 打印日期, 打印次数 From {调度管理} Where 车辆类型 = \'挂靠车\' or 车辆类型 = \'外网车\'" & Filter Else cmd.CommandText = "Se lect 锁定, 返单公司, 支付, 结算, 部门, 结算单号, 调度单号, 车牌号, 驾驶员, 车辆类型, 调度动态, 台数, 下游金额, 下游调整, 下游考核, 预借现金, 预借油卡, ISNULL(下游金额,0) + ISNULL(下游调整,0) - ISNULL(下游考核,0) - ISNULL(预借现金,0) - ISNULL(预借油卡,0) As 下游余款, 余款类型, 卡号, 结算备注, 调度备注, 承运单位, 结算员, 结算日期, 打印人, 打印日期, 打印次数 From {调度管理} Where 车辆类型 = \'挂靠车\' or 车辆类型 = \'外网车\'" End If Dim dt As DataTable = cmd.ExecuteReader() Dim Book As New XLS.Book Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter = "Excel文件| * .xlsx" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Book = New XLS.Book(dlg.FileName) 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 If MainTable.Cols(nms(c)).IsDate Then \'如果是日期列 Sheet.Cols(c).Style = st \'设置显示格式 End If Next For c As Integer = 0 To nms.Count - 1 Sheet(0, c).Value = nms(c) 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(dlg.FileName) Dim Result As DialogResult Result = MessageBox.Show("导出成功, 是否打开所导出文件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If Result = DialogResult.Yes Then Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If End If End If
|
-- 作者:有点蓝 -- 发布时间:2023/8/5 17:31: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
|