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
导出来以后,打开时,提示文件格式和扩展名不匹配,文件可能已经损坏或不安全