多在vb.net中使用Word模板 [英] Multi using Word template in vb.net
本文介绍了多在vb.net中使用Word模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试创建一个包含多个记录的报告,这些记录需要多次使用单词模板。但是通过我的下面的代码,每个下一条记录再次从第1页开始删除前一条记录。请建议..
谢谢
Atul
受保护的 Sub Button1_Click(发件人 As 对象,e As EventArgs)句柄 Button1.Click
oWord = CreateObject( Word.Application)
oWord.Visible = True
oDoc = oWord.Documents.Add( C:/Template1.dotx)
Dim i 作为 整数 = 0
Dim total As 整数 = 2
对于 i = < span class =code-digit> 0 总计
如果 i> 0 然后
oDoc.Content.InsertFile( C:/Template1.dotx)
结束 如果
oDoc.Bookmarks.Item( Bookmark1)。Range.Text = i
' 用于分页
Dim oRng As Word.Range
oRng = oDoc.Bookmarks .Item( \ endofdoc)。范围
oRng.InsertBreak(Word.WdBreakType) .wdPageBreak)
下一步
结束 苏b
解决方案
解决方案是使用带有起始范围值的范围并在每次循环后更改值
Hi All,
I am trying to create a report with multiple records which will require the word template to be used multiple times. But by my following code every next record starts again from Page 1 deleting the previous record. Please suggest..
Thanks
Atul
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click oWord = CreateObject("Word.Application") oWord.Visible = True oDoc = oWord.Documents.Add("C:/Template1.dotx") Dim i As Integer = 0 Dim total As Integer = 2 For i = 0 To total If i > 0 Then oDoc.Content.InsertFile("C:/Template1.dotx") End If oDoc.Bookmarks.Item("Bookmark1").Range.Text = i 'For page break Dim oRng As Word.Range oRng = oDoc.Bookmarks.Item("\endofdoc").Range oRng.InsertBreak(Word.WdBreakType.wdPageBreak) Next End Sub解决方案Solution was to use range with start range value and change the value after every loop
这篇关于多在vb.net中使用Word模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文