以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]导出数据为空的问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=187140) |
-- 作者:sunion0769 -- 发布时间:2023/6/25 22:21:00 -- [求助]导出数据为空的问题 在操作文档中有数据导出的代码如下,现在遇到的问题是: 如果表中某个单元格数据为空,导出的表显示该单元格的值是0,而不是空;如何让导出的表格和原始表格一样也为空? Dim dt As Table = Tables("表1") Dim nms() As String = {"A列", "B列", "C列", "D列"} \'要导出的列名 Dim caps() As String = {"A列", "B列", "C列", "D列"} \'对应的列标题 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) \'指定列标题 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
[此贴子已经被作者于2023/6/25 22:21:39编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/6/25 22:26:00 -- For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据 For c As Integer = 0 To nms.length - 1 if dt.rows(r).isnull(nms(c)) = false Sheet(r + 1, c).Value = dt.rows(r)(nms(c)) end if Next Next
|