以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 求助:生成Word报表问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=87271) |
||||
-- 作者:落叶孤影 -- 发布时间:2016/7/7 10:24:00 -- 求助:生成Word报表问题 老师,下面的代码是跟据当天的日期生成Word报表的,请问,如果按照选中的行生成Word报表的话,代码该怎么写呢? Dim drs As List(of DataRow) = DataTables("日报表").Select("日期 = #" & Date.Today & "#") \'筛选出符合条件的行 If drs.Count > 0 Then \'如果存在符合条件的行 Dim tm As String = ProjectPath & "Attachments\\test.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\练习.doc" \'指定目标文件 Dim wrt As New WordReport(Tables("日报表"),tm,fl) \'定义一个WordReport Dim sum1 As Double = DataTables("日报表").Compute("Sum(资金可用余额)","日期 = #" & Date.Today & "#") Dim sum2 As Double = DataTables("日报表").Compute("Sum(当天收入截至当天17时_现金回款额)","日期 = #" & Date.Today & "#") Dim sum3 As Double = DataTables("日报表").Compute("Sum(支出合计)","日期 = #" & Date.Today & "#") Dim str As String = "当日资金可用余额总计: " & sum1 & "万元,截至当日17时回款总计:" & Sum2 & "万元,当日支出总计" & sum3 & "万元" wrt.Replace("[第一部分]", str) str = "" Dim i As Integer = 1 For Each dr As DataRow In drs \'逐行生成报表 str &= i & "、" & dr("项目名称") & ":(1)当日资金可用余额:" & Format(dr("资金可用余额") ,"0.00") & "万元;" str &= vbcrlf i += 1 Next wrt.Replace("[第二部分]", str) wrt.Build wrt.Show() \'显示报表 End If |
||||
-- 作者:大红袍 -- 发布时间:2016/7/7 10:46:00 -- Dim t As Table = Tables("日报表") If t.rows.count > 0 Then Dim tm As String = ProjectPath & "Attachments\\test.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\练习.doc" \'指定目标文件 Dim wrt As New WordReport(Tables("日报表"),tm,fl) \'定义一个WordReport Dim sum1 As Double = DataTables("日报表").Compute("Sum(资金可用余额)","日期 = #" & Date.Today & "#") Dim sum2 As Double = DataTables("日报表").Compute("Sum(当天收入截至当天17时_现金回款额)","日期 = #" & Date.Today & "#") Dim sum3 As Double = DataTables("日报表").Compute("Sum(支出合计)","日期 = #" & Date.Today & "#") Dim str As String = "当日资金可用余额总计: " & sum1 & "万元,截至当日17时回款总计:" & Sum2 & "万元,当日支出总计" & sum3 & "万元" wrt.Replace("[第一部分]", str) str = "" Dim i As Integer = 1 For j As Integer = t.TopPosition To t.BottomPosition Dim dr As Row = t.rows(j) str &= i & "?" & dr("项目名称") & ":(1)当日资金可用余额:" & Format(dr("资金可用余额") ,"0.00") & "万元;" str &= vbcrlf i += 1 Next wrt.Replace("[第二部分]", str) wrt.Build wrt.Show() \'显示报表 end if |
||||
-- 作者:落叶孤影 -- 发布时间:2016/7/7 11:35:00 -- 首先感谢老师的及时回复!不过上面代码有点小问题,1、生成报表后不能自动打开,2、选中几行,生成的报表就会重复生成几次一样的文字。还请老师再帮忙看看! |
||||
-- 作者:大红袍 -- 发布时间:2016/7/7 11:54:00 -- 代码没问题,上传实例说明问题。 |
||||
-- 作者:落叶孤影 -- 发布时间:2016/7/7 12:30:00 -- 选中几行,生成的报表就会重复生成几次一样的文字。还请老师再帮忙看看!
|
||||
-- 作者:大红袍 -- 发布时间:2016/7/7 14:41:00 -- 改一改
\'\'\' |
||||
-- 作者:落叶孤影 -- 发布时间:2016/7/7 15:20:00 -- 谢谢老师! |