以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 导出EXCEL文件时如何只导出可见列 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=71092) |
-- 作者:santde -- 发布时间:2015/7/4 18:30:00 -- 导出EXCEL文件时如何只导出可见列 Dim lblDatatable As WinForm.Label = e.Form.Controls("lblDatatable")
这段代码导出了所有列 如何只导出可见列 [此贴子已经被作者于2015/7/4 18:34:32编辑过]
|
-- 作者:y2287958 -- 发布时间:2015/7/4 21:35:00 -- Dim t As Table = Tables("表A") Dim str As String = Date.Today & ".xls" Dim Book As New XLS.Book \'定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim lms As new List(of String) For Each c As Col In t.Cols If c.Visible = True lms.Add(c.Name) End If Next For i As Integer = 0 To lms.Count-1 Sheet(0,i).Value = lms(i) Next For r As Integer = 0 To t.Rows.Count-1 \'填入数据 For i As Integer = 0 To lms.Count-1 Sheet(r+1,i).Value = t.rows(r)(lms(i)) Next Next Book.Save(ProjectPath & "reports\\" & str) Dim Proc As New Process Proc.File = ProjectPath & "reports\\" & str Proc.Start()
|