以文本方式查看主题

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

--  作者:rgbjwjb
--  发布时间:2020/2/5 17:33:00
--  数据导出
我想用下面的代码实现选择部分记录导出,结果全部导出,请问怎么修改?谢谢!!

For Each t As Row In Tables("债权人基本情况表").GetCheckedRows
    Dim dt As Table = Tables("债权人基本情况表")
    Dim nms() As String = {"债权人","开户银行","银行账号","联系电话","身份证号码"} \'要导出的列名
    Dim caps() As String = {"债权人","开户银行","银行账号","联系电话","身份证号码"} \'对应的列标题
    Dim szs() As Integer = {100,120,120,150,200} \'对应的列宽
    Dim Book As New XLS.Book \'定义一个Excel工作簿
    Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
    For c As Integer = 0 To nms.length -1
        Sheet(0, c).Value = caps(c) \'指定列标题
        Sheet.Cols(c).Width = szs(c) \'指定列宽
    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
Next

--  作者:有点蓝
--  发布时间:2020/2/5 17:39:00
--  
    Dim nms() As String = {"债权人","开户银行","银行账号","联系电话","身份证号码"} \'要导出的列名
    Dim caps() As String = {"债权人","开户银行","银行账号","联系电话","身份证号码"} \'对应的列标题
    Dim szs() As Integer = {100,120,120,150,200} \'对应的列宽
    Dim Book As New XLS.Book \'定义一个Excel工作簿
    Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
    For c As Integer = 0 To nms.length -1
        Sheet(0, c).Value = caps(c) \'指定列标题
        Sheet.Cols(c).Width = szs(c) \'指定列宽
    Next
dim ts as list(of row) = Tables("债权人基本情况表").GetCheckedRows
    For r As Integer = 0 To ts.Count - 1 \'填入数据
        For c As Integer = 0 To nms.length -1
            Sheet(r +1, c).Value = ts(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