单词文档的页脚问题(VB.net和Word) [英] Problem in footer of a word document (VB.net and Word)

查看:133
本文介绍了单词文档的页脚问题(VB.net和Word)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好, 

Hello everyone, 

首先,这是我的第一篇文章,我希望我对这个论坛的规则没有任何错误。

First this is my first post and i hope i didn't make any mistakes regarding the rules of this forum.

我正在使用vb.net和WPF构建一个应用程序。

i'm building an application using vb.net and WPF.

在应用程序中,我需要单击一个按钮来生成一个单词导出,其中包含来自调用者页面。

In the app, i need to click on a button to generate a word export with data from the caller page.

导出工作正常,我设法得到要替换的值但是我对word文档的页脚有问题:

The export is working and i managed to get the values to replace however i have an issue with the footer of the word document :

我有一个页脚已经格式化的文本,里面有一个标签(< REF>),我想用值替换标签(例如:22587XA)。

i have a footer already formatted text with a tag inside (<REF>) and i want to replace the tag with the value (ex : 22587XA).

替换正在运行,但是它完全破坏了页脚的结构。

The replacement is working but it's completely destroying the structure of the footer.

这里是与此问题相关的代码: 

here's the code associated with this issue : 

If l_s_tag = "<REF>" Then
                    With l_o_wordTemplate.Sections.Item(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
                        .Text = l_o_wordTemplate.Sections.Item(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text.Replace(l_s_tag.ToString, l_o_dicoTags(l_s_tag).ToString)
                        '.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
                        '.Font.Size = 5
                    End With
                    With l_o_wordTemplate.Sections.Item(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
                        .Text = l_o_wordTemplate.Sections.Item(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Text.Replace(l_s_tag.ToString, l_o_dicoTags(l_s_tag).ToString)
                        '.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
                        '.Font.Size = 5
                    End With
End If

我正在尝试使用此代码更改第一页页脚(主页)和第一页中的所有其他页脚。

I'm trying in this code to alter the firstpage footer (primary) and all the other from the first page.

有没有办法在不改变结构的情况下替换页脚中的值?

Is there a way to replace a value in the footer without altering it's structure ?

感谢所有人谁能帮我解决这个问题。

Thanks to all people who'll help me resolve this issue.

祝你好运, 

Best regards, 

Leouarz

推荐答案

如果您准确知道页脚中的哪个位置< REF> tag是,您应该将范围对象设置为该范围并仅替换该范围;否则你应该使用Find找到标签(将范围重新设置为找到的范围),然后进行替换。
更简单的方法是将目标(即< REF>标记)范围加入书签并简单地更新书签,而无需专门处理标题。例如,假设< REF>标签已标记为'REF'。在VBA中,您需要的所有
需要:

If you know precisely where in the footer your <REF> tag is, you should set a range object to that range and replace just that range; otherwise you should use Find to locate the tag (which re-sets the range to the found range), then do the replace. An even simpler approach would be to bookmark the destination (i.e. <REF> tag) range and simply update the bookmark, without ever needing to specifically address the header. For example, suppose the <REF> tag is bookmarked 'REF'. In VBA, all you'd need is:

ActiveDocument.Bookmarks(" REF")。Range.Text =" My Text"

ActiveDocument.Bookmarks("REF").Range.Text = "My Text"

至于格式化,应该在使用之前在模板中完成,而不是在运行时。也就是说,您可以使用与更新其内容相同的方式将格式应用于书签范围。

As for the formatting, that should be done in the template before it is used, not at run-time. That said, you can apply formatting to the bookmarked range in the same way as you can update its content.


这篇关于单词文档的页脚问题(VB.net和Word)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆