以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  数据导出 导出数据不完整  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=180145)

--  作者:18920118515
--  发布时间:2022/9/30 12:49:00
--  数据导出 导出数据不完整
老师,帮忙看下代码,数据导出后 “置换指标性质” 列 数据导出不完整,部分行的该列有数据,但导出后为空白,您受累指导下

If Tables("销售订单结算窗口_Table2").rows.count > 0 Then
    Dim dt As Table = Tables("销售订单结算窗口_Table2")
    Dim nms() As String = {"销售顾问","客户姓名","电话号码","证件号码","身份证地址","订车日期","车型","配置","外观颜色","内饰颜色","VIN码","整车收入_裸车收入","整车收入_支付置换补贴","整车收入_收入合计","整车成本","返利合计","裸车利润","置换指标性质","二手车销售利润","上牌收入","上牌成本","出库费收入","上牌利润","装具收入","装具成本","装具利润","付款方式","贷款金融公司","贷款期数","贷款金额","贷款服务费收入","贷款利润","保险利润","边际利润","利润总额","发票类型","开票日期","发票号","整车开票价格","整车开票差价","售车申报日期","结算日期"} \'要导出的列名
    Dim caps() As String = {"销售顾问","客户姓名","电话号码","证件号码","身份证地址","订车日期","车型","配置","外观颜色","内饰颜色","VIN码","整车收入","支付置换补贴","整车收入合计","整车成本","返利合计","裸车利润","置换指标性质","二手车销售利润","上牌收入","上牌成本","出库费收入","上牌利润","装具收入","装具成本","装具利润","付款方式","贷款金融公司","贷款期数","贷款金额","贷款服务费收入","贷款利润","保险利润","边际利润合计","利润总额","发票类型","开票日期","发票号","整车开票价格","整车开票差价","售车申报日期","结算日期"}  \'对应的列标题
    Dim szs() As Integer = {70,100,110,170,300,90,90,250,90,90,190,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90} \'对应的列宽
    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
Else
    MessageBox.Show("没有要导出的数据,请重试刷新")
    e.Cancel = True
End If

--  作者:有点蓝
--  发布时间:2022/9/30 13:38:00
--  
代码没有问题。如果导出没有数据,说明Tables("销售订单结算窗口_Table2")表格本身就没有这些数据