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


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

主题:导出数据

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/16 14:53:00 [显示全部帖子]

 Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
    Dim dt As Table = Tables("表A")
    Dim nms() As String =  "第一列,第二列,第三列,第四列,第五列".split(",")
    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"
    st.BorderTop = XLS.LineStyleEnum.Thin
    st.BorderBottom = XLS.LineStyleEnum.Thin
    st.BorderLeft = XLS.LineStyleEnum.Thin
    st.BorderRight = XLS.LineStyleEnum.Thin
    st.BorderColorTop = Color.Red
    st.BorderColorBottom = Color.Red
    st.BorderColorLeft = Color.Red
    st.BorderColorRight = Color.Red
   
   
    Dim style As XLS.Style = Book.NewStyle '日期列的显示格式
    Style.BorderTop = XLS.LineStyleEnum.Thin
    Style.BorderBottom = XLS.LineStyleEnum.Thin
    Style.BorderLeft = XLS.LineStyleEnum.Thin
    Style.BorderRight = XLS.LineStyleEnum.Thin
    Style.BorderColorTop = Color.Red
    Style.BorderColorBottom = Color.Red
    Style.BorderColorLeft = Color.Red
    Style.BorderColorRight = Color.Red
    For c As Integer = 0 To nms.length -1
        Dim dc As Col = dt.Cols(c)
        Sheet(0, c).Value = dc.Caption '指定列标题
        Sheet.Cols(c).Width = dc.Width '指定列宽
        sheet(0,c).style = style
    Next
    For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
        For c As Integer = 0 To nms.length -1
            If dt.Cols(nms(c)).IsDate Then '如果是日期列
                Sheet(r+1,c).Style = st '设置显示格式
            Else
                Sheet(r+1,c).Style = style
            End If
            Sheet(r +1, c).Value = dt.rows(r)(nms(c))
        Next
    Next
   
    Book.Save(dlg.FileName)
    Dim Proc As New Process
    Proc.File = dlg.FileName
    Proc.Start()
End If

[此贴子已经被作者于2017/10/16 14:53:30编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/17 9:32:00 [显示全部帖子]

e.sender.Items.Clear
For Each c As Col In Tables("表A").Cols
    e.sender.Items.add(c.name)
Next

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/17 9:56:00 [显示全部帖子]

Dim ccb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
Dim ws As String =  Tables("表A").getColVisibleWidth
If ccb.Text > "" Then
    Dim lst As new List(of String)
    lst.AddRange(ccb.Text.Split(","))
    For Each c As Col In Tables("表A").Cols
        c.Visible = lst.Contains(c.Name)
    Next
End If
Dim flg As New  SaveExcelFlags
flg.RowNumber = True
flg.CellStyle = True
flg.VisibleOnly = True
Tables("表A").SaveExcel("f:\123.xls","表A",flg)

Tables("表A").SetColVisibleWidth(ws)
Dim Proc As New Process
Proc.File = "f:\123.xls"
Proc.Start()

[此贴子已经被作者于2017/10/17 10:15:30编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/17 10:15:00 [显示全部帖子]

Dim ccb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
Dim ws As String =  Tables("表A").getColVisibleWidth
If ccb.Text > "" Then
    Dim lst As new List(of String)
    lst.AddRange(ccb.Text.Split(","))
    For Each c As Col In Tables("表A").Cols
        c.Visible = lst.Contains(c.Name)
    Next
End If
Dim flg As New  SaveExcelFlags
flg.RowNumber = True
flg.CellStyle = True
flg.VisibleOnly = True
Tables("表A").SaveExcel("f:\123.xls","表A",flg)

Tables("表A").SetColVisibleWidth(ws)
Dim Proc As New Process
Proc.File = "f:\123.xls"
Proc.Start()


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/17 10:34:00 [显示全部帖子]

请用11楼代码。或者用2楼代码。

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/17 11:08:00 [显示全部帖子]

Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
    Dim ccb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
    Dim ws As String =  Tables("表A").getColVisibleWidth
    If ccb.Text > "" Then
        Dim lst As new List(of String)
        lst.AddRange(ccb.Text.Split(","))
        For Each c As Col In Tables("表A").Cols
            c.Visible = lst.Contains(c.Name)
        Next
    End If
    Dim flg As New  SaveExcelFlags
    flg.RowNumber = True
    flg.CellStyle = True
    flg.VisibleOnly = True
    Tables("表A").SaveExcel(dlg.FileName,"表A",flg)
   
    Tables("表A").SetColVisibleWidth(ws)
    Dim Proc As New Process
    Proc.File = dlg.FileName
    Proc.Start()
End If

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/23 15:02:00 [显示全部帖子]

看你TextChanged是否触发,如果触发了,就是【确定】。

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/23 16:20:00 [显示全部帖子]

选择否的时候,不要重复触发代码

 

Else
systemready = false
    Dim sbxh As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
    sbxh.Value =""
systemready = true
End If


 回到顶部