book.AddDataTable("客户对账",sqlstr)
book.AddDataTable("客户对账明细",dt)
book.AddRelation("客户对账","对账编号","客户对账明细","对账编号")
Book.Build()
明细表大概2千多条数据,生成过程中程序闪退,是数据量多的问题么?有什么解决办法么?
我觉得也不应该,但我是用模板导出,数据都加载了,就是build过程闪退,就是上面的主要代码,怎么会死循环呢
Dim dt As DataTable
dt = ExecSQLGetDataTable(sql1,"V16Data")
'MessageBox.show(dt.DataRows.Count)
Dim Book As New XLS.Book(fp)
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
dlg.FileName=tr("客户简称") & tr("对账年份") & tr("对账月份") & "对账表.xlsx"
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim fl As String = dlg.FileName
book.AddDataTable("客户对账","V16Data",sqlstr)
book.AddDataTable("客户对账明细",dt)
book.AddRelation("客户对账","对账编号","客户对账明细","对账编号") '建立关联
'MessageBox.show("start build")
Book.Build() '生成细节区
Book.Save(fl) '保存工作簿
'MessageBox.Show("end")
Dim Proc As New Process '打开工作簿
Proc.File = fl
Proc.Start()
End If
测试了800多条数据正常,很奇怪(有sql语句的地方发不出来,改成变量了)。
这样试试
Dim Book As New XLS.Book(fp)
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
dlg.FileName=tr("客户简称") & tr("对账年份") & tr("对账月份") & "对账表.xlsx"
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim fl As String = dlg.FileName
book.AddDataTable("客户对账","V16Data",sqlstr)
book.AddDataTable("客户对账明细","V16Data",sql1)
book.AddRelation("客户对账","对账编号","客户对账明细","对账编号") '建立关联
'MessageBox.show("start build")
Book.Build() '生成细节区
Book.Save(fl) '保存工作簿
'MessageBox.Show("end")
Dim Proc As New Process '打开工作簿
Proc.File = fl
Proc.Start()
End If
蓝老大,按你那个代码不行,其实原来就是你这种写法,不行才换的,还是闪退。还麻烦您看一下怎么解决比较好
解决了,蓝老大,客户做的模板下面有多余的行,有异常。晕死