以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 怎么利用代码将两个甚至多个不同的excel表合并成一个《表彰统计表》文件,然后将对应的个人表彰统计表 集体表彰统计表 成为这个文件里面的两个工作表内容呢? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=164875) |
||||
-- 作者:cnsjroom -- 发布时间:2021/5/7 16:15:00 -- 怎么利用代码将两个甚至多个不同的excel表合并成一个《表彰统计表》文件,然后将对应的个人表彰统计表 集体表彰统计表 成为这个文件里面的两个工作表内容呢? Dim fl As String = ProjectPath & "Attachments\\附件地址\\" & format(date.today,"D") & "个人表彰统计表.xlsx" Dim Book As New XLS.Book(ProjectPath & "Attachments\\【模板】表彰(个人)统计表.xlsx") book.AddDataTable("表彰","智慧党建","Sel ect * from {表彰} where 表彰类别=\'个人表彰\'") Book.Build() Book.Save(fl) Dim fl1 As String = ProjectPath & "Attachments\\附件地址\\" & format(date.today,"D") & "集体表彰统计表.xlsx" Dim Book1 As New XLS.Book(ProjectPath & "Attachments\\【模板】表彰(集体)统计表.xlsx") book1.AddDataTable("表彰","智慧党建","Sel ect * from {表彰} where 表彰类别=\'集体表彰\'") Book1.Build() Book1.Save(fl1) 上述代码会生成两个不同的统计表 怎么利用代码将两个甚至多个不同的excel表合并成一个《表彰统计表》文件,然后将对应的个人表彰统计表 集体表彰统计表 成为这个文件里面的两个工作表内容呢?
|
||||
-- 作者:有点蓝 -- 发布时间:2021/5/7 16:22:00 -- 在模板里添加2个sheet,然后设置不同的条件即可,下面模板和代码我测试没有问题 Dim Book As New XLS.Book(ProjectPath & "Attachments\\出库单.xls") Dim fl As String = ProjectPath & "Reports\\出库单.xls" book.AddDataTable("出库","","Select * from {出库}") \'添加父表 book.AddDataTable("出库明细","","Select * from {出库明细}") \'添加子表 book.AddRelation("出库","出库单编号","出库明细","出库单编号") \'建立关联 Book.Build() \'生成细节区 Book.Save(fl) \'保存工作簿 Dim Proc As New Process \'打开工作簿 Proc.File = fl Proc.Start() |
||||
-- 作者:cnsjroom -- 发布时间:2021/5/7 18:20:00 -- 回复:(有点蓝)在模板里添加2个sheet,然后设置不同... 如果是已经创建好了一个总的工作表 且定义了两个细工作表 老师的上述方法可以完美使用 当前我的环境是: 已经有这两个单独的表:且表之间无关联 怎么用代码将这两个不同的表合并成一个总表 如老师给出的一个excel文件 两个不同的细节(在我不需要提前定义好细节的前提下) 下述代码如何修正呢? Dim fl As String = ProjectPath & "Attachments\\附件地址\\" & format(Date.today,"D") & "个人表彰统计表.xlsx" Dim Book As New XLS.Book(ProjectPath & "Attachments\\【模板】表彰(个人)统计表.xlsx") book.AddDataTable("表彰","智慧党建","Sel ect * from {表彰} where 表彰类别=\'个人表彰\'") Book.Build() Book.Save(fl) Dim fl1 As String = ProjectPath & "Attachments\\附件地址\\" & format(Date.today,"D") & "集体表彰统计表.xlsx" Dim Book1 As New XLS.Book(ProjectPath & "Attachments\\【模板】表彰(集体)统计表.xlsx") book1.AddDataTable("表彰","智慧党建","Sel ect * from {表彰} where 表彰类别=\'集体表彰\'") Book1.Build() Book1.Save(fl1) 最终实现文件效果:
[此贴子已经被作者于2021/5/7 18:24:27编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2021/5/8 8:33:00 -- 都是同一个表数据,把条件放到模板里即可 Dim fl As String = ProjectPath & "Attachments\\附件地址\\" & format(Date.today,"D") & "个人表彰统计表.xlsx" Dim Book As New XLS.Book(ProjectPath & "Attachments\\【模板】表彰统计表.xlsx") book.AddDataTable("表彰","智慧党建","Select * from {表彰}") Book.Build() Book.Save(fl) |