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


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

主题:导出数据

帅哥哟,离线,有人找我吗?
有点甜
  11楼 | 信息 | 搜索 | 邮箱 | 主页 | 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()


 回到顶部
帅哥,在线噢!
cd_tdh
  12楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐精 帖子:3069 积分:20526 威望:0 精华:0 注册:2016/3/28 16:57:00
  发帖心情 Post By:2017/10/17 10:33:00 [只看该作者]

麻烦老师在看一下,这样导出来没有数据呢

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"
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 dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
    Book.Save(dlg.FileName)
    Tables("表A").SetColVisibleWidth(ws)
    Dim Proc As New Process
    Proc.File = dlg.FileName
    Proc.Start()
End If


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


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

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

 回到顶部
帅哥,在线噢!
cd_tdh
  14楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐精 帖子:3069 积分:20526 威望:0 精华:0 注册:2016/3/28 16:57:00
  发帖心情 Post By:2017/10/17 11:06:00 [只看该作者]

我是自定义存储路径和名称

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  15楼 | 信息 | 搜索 | 邮箱 | 主页 | 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

 回到顶部
帅哥,在线噢!
cd_tdh
  16楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐精 帖子:3069 积分:20526 威望:0 精华:0 注册:2016/3/28 16:57:00
  发帖心情 Post By:2017/10/23 14:19:00 [只看该作者]

以下是引用有点甜在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

老师,选择列后,怎么判断我是否点击了确定或是取消,点击确定直接就导出选择的列,这儿该怎么处理。


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


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

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

 回到顶部
帅哥,在线噢!
cd_tdh
  18楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐精 帖子:3069 积分:20526 威望:0 精华:0 注册:2016/3/28 16:57:00
  发帖心情 Post By:2017/10/23 15:46:00 [只看该作者]

以下是引用有点甜在2017/10/23 15:02:00的发言:
看你TextChanged是否触发,如果触发了,就是【确定】。

老师,代码如下,我选择了NO,多执行了一次MessageBox,需要在点一次NO才行,哪儿有问题?

Dim Result As DialogResult
Result = MessageBox.Show("你确定导出选择数据列的数据吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes  Then
    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
Else
    Dim sbxh As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
    sbxh.Value =""
End If

 

问题就是我在复选框点击确定,MessageBox弹出之前,已经写入值,所以多弹出了一次MessageBox,能否点击复选框确定不写入或是其他处理方式,点击MessageBox确定时在写执行CheckedComboBox1。

[此贴子已经被作者于2017/10/23 16:04:54编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  19楼 | 信息 | 搜索 | 邮箱 | 主页 | 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


 回到顶部
帅哥,在线噢!
cd_tdh
  20楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐精 帖子:3069 积分:20526 威望:0 精华:0 注册:2016/3/28 16:57:00
  发帖心情 Post By:2017/10/23 16:59:00 [只看该作者]

完美解决,谢谢老师。

 回到顶部
总数 20 上一页 1 2