Foxtable(狐表)用户栏目专家坐堂 → 数据导出


  共有4116人关注过本帖树形打印复制链接

主题:数据导出

帅哥哟,离线,有人找我吗?
rgbjwjb
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:651 积分:6614 威望:0 精华:0 注册:2016/12/27 21:05:00
数据导出  发帖心情 Post By: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

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111393 积分:567029 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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


 回到顶部