Foxtable(狐表)用户栏目专家坐堂 → 条件导出excl


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

主题:条件导出excl

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


加好友 发短信
等级:婴狐 帖子:11 积分:193 威望:0 精华:0 注册:2017/6/1 11:57:00
条件导出excl  发帖心情 Post By:2018/8/25 13:45:00 [只看该作者]

表中,发货列条件满足 为“已发货"和”订单状态为”确定“的订单,则本行的数据就可以导出excl,这个应该怎么加入到下面的公式中?



图片点击可在新窗口打开查看此主题相关图片如下:表a.jpg
图片点击可在新窗口打开查看



Dim dt As Table = Tables("订单管理")
Dim nms() As String = {"订单编号","订单日期","客户名称","细分门型","料型","颜色","门高","门宽","扇数","玻璃高","玻璃宽","玻璃类型","玻璃款式","生产备注"} '要导出的列名 
Dim caps() As String = {"订单编号","订单日期","客户名称","细分门型","料型","颜色","门高","门宽","扇数","玻璃高","玻璃宽","玻璃类型","玻璃款式","生产备注"} '对应的列标题 
Dim szs() As Integer = {100,100,100,100,100,100,60,60,40,60,60,60,100,100} '对应的列宽 
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" 
For c As Integer = 0 To nms.length -1 
    Sheet(0, c).Value = caps(c) '指定列标题
    Sheet.Cols(c).Width = szs(c) '指定列宽
    If dt.Cols(nms(c)).IsDate Then '如果是日期列
        Sheet.Cols(c).Style = st '设置显示格式
    End If
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


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


加好友 发短信
等级:婴狐 帖子:11 积分:193 威望:0 精华:0 注册:2017/6/1 11:57:00
  发帖心情 Post By:2018/8/25 13:46:00 [只看该作者]

如何在这个导出代码前面加个条件?

 回到顶部
帅哥,在线噢!
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111414 积分:567140 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2018/8/25 14:12:00 [只看该作者]

dt.filter = "发货状态='已发货' and 订单状态='确定'"

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


加好友 发短信
等级:婴狐 帖子:11 积分:193 威望:0 精华:0 注册:2017/6/1 11:57:00
  发帖心情 Post By:2018/8/26 9:16:00 [只看该作者]

应该怎么加在里面啊?我加进去,把表格内的全部都筛选掉了···这个代码加在哪里?
[此贴子已经被作者于2018/8/26 9:16:51编辑过]

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


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

比如

 

Dim dt As Table = Tables("订单管理")
dt.filter = "发货状态='已发货' and 订单状态='确定'"
Dim nms() As String = {"订单编号","订单日期","客户名称","细分门型","料型","颜色","门高","门宽","扇数","玻璃高","玻璃宽","玻璃类型","玻璃款式","生产备注"} '要导出的列名
Dim caps() As String = {"订单编号","订单日期","客户名称","细分门型","料型","颜色","门高","门宽","扇数","玻璃高","玻璃宽","玻璃类型","玻璃款式","生产备注"} '对应的列标题
Dim szs() As Integer = {100,100,100,100,100,100,60,60,40,60,60,60,100,100} '对应的列宽
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"
For c As Integer = 0 To nms.length -1
    Sheet(0, c).Value = caps(c) '指定列标题
    Sheet.Cols(c).Width = szs(c) '指定列宽
    If dt.Cols(nms(c)).IsDate Then '如果是日期列
        Sheet.Cols(c).Style = st '设置显示格式
    End If
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


 回到顶部