以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]导出窗口多个表到同一个文件的多个sheet (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=183987) |
-- 作者:chnfo -- 发布时间:2022/11/22 10:50:00 -- [求助]导出窗口多个表到同一个文件的多个sheet If Forms("MReport").Opened Then Dim ym As Integer = 202402 Dim t1 As Table = Forms("MReport").Controls("Table1").Table \'这个表是在窗口中构建的临时表,窗口关闭就删除的 Dim t2 As Table = Forms("MReport").Controls("Table2").Table \'这个是绑定数据表的副本 Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter = "EXCEL文件|*.xls;*.xlsx" \'设置筛选器 dlg.FileName = ym If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim ex As New Exporter ex.SourceTableName = t1.DataTable.Name \'指定导出表 ex.filepath = dlg.FileName ex.NewTableName = "明细" ex.Export() \'开始导出 ex.SourceTableName = t2.DataTable.Name \'指定导出表 ex.filepath = dlg.FileName ex.NewTableName = "汇总" ex.Export() \'开始导出 End If end if 导出来以后,打开时,提示文件格式和扩展名不匹配,文件可能已经损坏或不安全 |
-- 作者:有点蓝 -- 发布时间:2022/11/22 10:59:00 -- If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim ex As New Exporter ex.SourceTableName = t1.DataTable.Name \'指定导出表 ex.filepath = dlg.FileName ex.NewTableName = "明细" if dlg.FileName like "*.xlsx" then ex.Format = "Excel2007" else ex.Format = "Excel" end if ex.Export() \'开始导出 ex = New Exporter ex.SourceTableName = t2.DataTable.Name \'指定导出表 ex.filepath = dlg.FileName ex.NewTableName = "汇总" if dlg.FileName like "*.xlsx" then ex.Format = "Excel2007" else ex.Format = "Excel" end if ex.Export() \'开始导出 [此贴子已经被作者于2022/11/22 10:59:52编辑过]
|