以文本方式查看主题 - 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=91267) |
||||
-- 作者:jyh7081 -- 发布时间:2016/10/5 23:47:00 -- [求助]在窗口中预览word报表时存在的问题 项目附件中有3种不同的word模板,当点击word报表(或在窗口WebBrowser控件中)预览时,存在如下问题,能否解决: 1、当数据表某项无数据时,报表对应此位置显示空行;怎样删掉? 2、数据表中含有换行符时,报表对应位置显示多余空格;或者内容由数行变为一行;怎样保持不变? ----------------------------------------------------------------------------------------------- 数据表样式: ----------------------------------------------------------------------------------------------- 其中一种模板预览时的情况: ----------------------------------------------------------------------------------------------- 附件:
[此贴子已经被作者于2016/10/5 23:52:25编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2016/10/6 8:59:00 -- 同样的问题你已经问过了 http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=89554
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=89633 |
||||
-- 作者:jyh7081 -- 发布时间:2016/10/6 18:45:00 -- 预览可以随时查看数据全貌,比生成报表后再查看方便些,但是遇到问题了,请指教。 第一段代码,可运行(建立一个WebBrowser控件窗口):\'\'\' Dim wbr As WinForm.WebBrowser = e.Form.Controls("WebBrowser1") Dim tm As String = ProjectPath & "Attachments\\11(不含表格).doc" Dim fl As String = ProjectPath & "Reports\\11(不含表格)doc" Dim wrt As New WordReport(Tables("表AA"),tm,fl) wrt.Build() wrt.Quit() wbr.Address = fl 第二段代码是去段落空行的,加上后就不能运行了: Dim app As New MSWord.Application try Dim doc = app.Documents.Open(fl) doc.Content.Find.Execute(FindText:="^l", replacewith:="^p", Replace:=2) doc.Content.Find.Execute(FindText:="^13", replacewith:="^p", Replace:=2) For Each k As object In doc.Paragraphs k.Range.Select If Len(k.Range.text) = 1 Then k.Range.Delete Do If app.Selection.Characters(1).Text = Chr(10) Then app.Selection.Characters(1).Delete Loop Until app.Selection.Characters(1).Text <> Chr(10) Next \'删除表格空行: Dim tb As Object, r As Object With Doc For Each tb In .Tables For Each r In tb.Rows r.Range.Find.Execute(FindText:="^l", replacewith:="^p", Replace:=2) r.Range.Find.Execute(FindText:=" ", replacewith:="", Replace:=2) r.Range.Find.Execute(FindText:="^w", replacewith:="", Replace:=2) If Len(Replace(Replace(r.Range.Text, vbCr, ""), Chr(7), "")) = 0 Then r.Delete Next Next End With doc.save app.quit catch ex As exception msgbox(ex.message) app.quit End try |
||||
-- 作者:有点蓝 -- 发布时间:2016/10/7 8:46:00 -- Dim wbr As WinForm.WebBrowser = e.Form.Controls("WebBrowser1") Dim tm As String = ProjectPath & "Attachments\\11(不含表格).doc" Dim fl As String = ProjectPath & "Reports\\11(不含表格)doc" Dim wrt As New WordReport(Tables("表AA"),tm,fl) wrt.Build() wrt.Quit() Dim app As New MSWord.Application try Dim doc = app.Documents.Open(fl) doc.Content.Find.Execute(FindText:="^l", replacewith:="^p", Replace:=2) doc.Content.Find.Execute(FindText:="^13", replacewith:="^p", Replace:=2) For Each k As object In doc.Paragraphs k.Range.Select If Len(k.Range.text) = 1 Then k.Range.Delete Do If app.Selection.Characters(1).Text = Chr(10) Then app.Selection.Characters(1).Delete Loop Until app.Selection.Characters(1).Text <> Chr(10) Next \'删除表格空行: Dim tb As Object, r As Object With Doc For Each tb In .Tables For Each r In tb.Rows r.Range.Find.Execute(FindText:="^l", replacewith:="^p", Replace:=2) r.Range.Find.Execute(FindText:=" ", replacewith:="", Replace:=2) r.Range.Find.Execute(FindText:="^w", replacewith:="", Replace:=2) If Len(Replace(Replace(r.Range.Text, vbCr, ""), Chr(7), "")) = 0 Then r.Delete Next Next End With doc.save app.quit catch ex As exception msgbox(ex.message) app.quit End try wbr.Address = fl |