Foxtable(狐表)用户栏目专家坐堂 → 导出EXCEL文件时如何只导出可见列


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

主题:导出EXCEL文件时如何只导出可见列

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


加好友 发短信
等级:童狐 帖子:274 积分:2293 威望:0 精华:0 注册:2015/6/14 18:33:00
导出EXCEL文件时如何只导出可见列  发帖心情 Post By:2015/7/4 18:30:00 [只看该作者]

Dim lblDatatable As WinForm.Label = e.Form.Controls("lblDatatable")
Dim dt As Table = e.Form.Controls("Table1").Table
Dim str As String = _tables3_ & Format(Date.Now, "yyyyMMddHHmmss") & ".xls"
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim Style As Xls.Style = Book.NewStyle '新建一个样式
Style.BackColor = Color.Red '样式的背景颜色设为红色
For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
    Sheet(0, c).Value = dt.Cols(c).Name
Next
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
    For c As Integer = 0 To dt.Cols.Count -1
        Sheet(r +1, c).Value = dt.rows(r)(c)
    Next
    'If dt.rows(r)("折扣") >= 0.15 Then '如果折扣大于等于0.15
    'Sheet(r + 1,dt.Cols("折扣").Index).Style = Style '设置折扣单元格的样式
    'End  If
Next
Dim St2 As XLS.Style = Book.NewStyle
Dim St3 As XLS.Style = Book.NewStyle
St2.Format = "yyyy-MM-dd"
St3.Format = "yyyy-MM-dd hh:mm:ss"
Sheet.Cols(dt.Cols("出厂日期").Index).Style = st2
Sheet.Cols(dt.Cols("安装日期").Index).Style = st2
Sheet.Cols(dt.Cols("进厂日期").Index).Style = st2
Sheet.Cols(dt.Cols("填报时间").Index).Style = st3
'打开工作簿
Book.Save(ProjectPath & "reports\" & str)
Dim Proc As New Process
Proc.File = ProjectPath & "reports\" & str
Proc.Start()

 

这段代码导出了所有列

如何只导出可见列

[此贴子已经被作者于2015/7/4 18:34:32编辑过]

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


加好友 发短信
等级:狐神 帖子:4752 积分:34568 威望:0 精华:0 注册:2008/8/31 22:44:00
  发帖心情 Post By: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()

 回到顶部