Foxtable(狐表)用户栏目专家坐堂 → [求助]导出非关联表数据并字段分工作表


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

主题:[求助]导出非关联表数据并字段分工作表

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


加好友 发短信
等级:童狐 帖子:260 积分:3307 威望:0 精华:0 注册:2016/5/21 14:28:00
[求助]导出非关联表数据并字段分工作表  发帖心情 Post By:2018/5/10 9:09:00 [只看该作者]

如题:
比如说有一张"订单表"和一张"物料表",根据订单号导出物料清单,并根据供应商分类。


以下代码只能导出某用户名所输入的所有物料信息,怎么才能只导出在订单表中选择的行所对应的相关物料信息。
Dim nams As List(Of String) = DataTables("备料明细").GetValues("供货方","下单人 = '" & _UserName & "'")
Dim App As New MSExcel.Application
Dim bname As String = "d:\物料采购\物料采购清单.xlsx"
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Add
Dim ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
For Each nam As String In nams
    Dim Book As New XLS.Book ( ProjectPath & "Attachments\物料采购清单.xls" ) '调用模板
    Dim sheet As XLS.Sheet = Book.Sheets(0)
    Tables("备料明细").filter = "供货方 = '" & nam & "' and 下单人 = '" & _UserName & "'"
    Book.Build()
    Dim fl As String = "d:\物料采购\" & nam & ".xls"
    Book.Save(fl) '保存工作簿
    Dim Wb_temp As MSExcel.WorkBook = App.WorkBooks.Open(fl)
    Dim Ws_temp As MSExcel.WorkSheet = wb_temp.WorkSheets(1)
    Ws_temp.name = nam
    Ws_temp.Copy(System.Reflection.Missing.Value, ws)
    wb_temp.close(False, System.Reflection.Missing.Value, System.Reflection.Missing.Value)
Next
ws.delete
Wb.saveas(bname)
App.Quit
Dim Proc As New Process '打开工作簿
Proc.File = bname
Proc.Start()

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


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

Dim cr As Row = Tables("订单").Current

Dim nams As List(Of String) = DataTables("备料明细").GetValues("供货方","订单号 = '" & cr("订单号") & "'")
Dim App As New MSExcel.Application
Dim bname As String = "d:\物料采购\物料采购清单.xlsx"
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Add
Dim ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
For Each nam As String In nams
    Dim Book As New XLS.Book ( ProjectPath & "Attachments\物料采购清单.xls" ) '调用模板
    Dim sheet As XLS.Sheet = Book.Sheets(0)
    Tables("备料明细").filter = "供货方 = '" & nam & "' and 订单号 = '" & cr("订单号") & "'"
    Book.Build()
    Dim fl As String = "d:\物料采购\" & nam & ".xls"
    Book.Save(fl) '保存工作簿
    Dim Wb_temp As MSExcel.WorkBook = App.WorkBooks.Open(fl)
    Dim Ws_temp As MSExcel.WorkSheet = wb_temp.WorkSheets(1)
    Ws_temp.name = nam
    Ws_temp.Copy(System.Reflection.Missing.Value, ws)
    wb_temp.close(False, System.Reflection.Missing.Value, System.Reflection.Missing.Value)
Next
ws.delete
Wb.saveas(bname)
App.Quit
Dim Proc As New Process '打开工作簿
Proc.File = bname
Proc.Start()

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


加好友 发短信
等级:童狐 帖子:260 积分:3307 威望:0 精华:0 注册:2016/5/21 14:28:00
  发帖心情 Post By:2018/5/10 9:41:00 [只看该作者]

如果订单表选择的不知一行而是多行改怎么办?

[此贴子已经被作者于2018/5/10 9:41:43编辑过]

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


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

Dim t As Table = Tables("订单")
Dim filter As String = "1=2"
For i As Integer = t.TopPosition To t.BottomPosition
    filter &= " or 订单号 = '" & t.rows(i)("订单号") & "'"
Next
Dim nams As List(Of String) = DataTables("备料明细").GetValues("供货方",filter)
Dim App As New MSExcel.Application
Dim bname As String = "d:\物料采购\物料采购清单.xlsx"
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Add
Dim ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
For Each nam As String In nams
    Dim Book As New XLS.Book ( ProjectPath & "Attachments\物料采购清单.xls" ) '调用模板
    Dim sheet As XLS.Sheet = Book.Sheets(0)
    Tables("备料明细").filter = "供货方 = '" & nam & "' and (" & filter & ")"
    Book.Build()
    Dim fl As String = "d:\物料采购\" & nam & ".xls"
    Book.Save(fl) '保存工作簿
    Dim Wb_temp As MSExcel.WorkBook = App.WorkBooks.Open(fl)
    Dim Ws_temp As MSExcel.WorkSheet = wb_temp.WorkSheets(1)
    Ws_temp.name = nam
    Ws_temp.Copy(System.Reflection.Missing.Value, ws)
    wb_temp.close(False, System.Reflection.Missing.Value, System.Reflection.Missing.Value)
Next
ws.delete
Wb.saveas(bname)
App.Quit
Dim Proc As New Process '打开工作簿
Proc.File = bname
Proc.Start()


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


加好友 发短信
等级:童狐 帖子:260 积分:3307 威望:0 精华:0 注册:2016/5/21 14:28:00
  发帖心情 Post By:2018/5/10 10:25:00 [只看该作者]

谢谢!

 回到顶部