水印Awalys应用于奇数页 [英] Watermark Awalys Applied to Odd Pages

查看:109
本文介绍了水印Awalys应用于奇数页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过在标题中添加形状对象,将WordArt"水印"应用于许多文档。

但是对于奇数/偶数页眉不同的文档,水印只会应用于奇数页眉...即使我使用'Section.Headers [Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages]'来指定偶数页眉!

无论我尝试什么,我都无法将水印应用于奇数/偶数页面标题设置不同的文档上的偶数页面。

我的代码:


I'm applying a WordArt 'Watermark' to many documents by adding a shape object to the header. 

However for documents where odd/even page headers are different, the Watermark only gets applied to the odd page headers... even when I use 'Section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages]' to specify the even page headers! 

No matter what I try, I can't get the Watermark applied to even pages on documents where odd/even page headers are set to be different.

My code:

            object fileName = docPath;
            Word.Document nDoc = nWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            Word.Shape nShape = null;

            foreach (Word.Section section in nDoc.Sections)
            {
                nShape = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, wmText, "Arial", (float)36, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, ref oMissing);

                nShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                nShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
                nShape.Fill.Solid();
                nShape.Fill.ForeColor.RGB = (Int32)Word.WdColor.wdColorGray20;
                nShape.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
                nShape.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
                nShape.Left = (float)Word.WdShapePosition.wdShapeCenter;
                nShape.Top = (float)Word.WdShapePosition.wdShapeCenter;
            }
            nDoc.Close(ref saveChanges, ref oMissing, ref oMissing);

推荐答案

嗨Nathan

在AddTextEffect中你遗漏了最后一个,可选参数锚点。这告诉Word应该固定Shape的范围,我相信这就是你遇到问题的原因。
Word.Range rng = section.Headers [Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages] .Range;
对象oRng = rng;

现在使用rng而不是丢失作为方法的最后一个参数,看看是否有所不同。

原因:在对于页眉和页脚中使用的所有形状,Word都有一个中央存储空间。如果未指定锚定范围,则Shape可能不会放置在该位置,而是放置在默认位置。您可能想检查在该部分的奇数页脚中是否没有多个艺术字相互叠加...
Hi Nathan

In the AddTextEffect you've left out the last, optional parameter Anchor. This tells Word to what range the Shape should be anchored, and I believe this is why you're having problems.

Word.Range rng = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range;
object oRng = rng;

Now use rng instead of missing as the last parameter of the method and see if that makes a difference.

Reason: In the background, Word has a central storage for all shapes used in headers and footers. If you don't specify the anchoring range, the Shape may not be placed in that position, but in the default position. You may want to check whether there aren't multiple WordArt overlaying each other in the odd page footer of the section...


这篇关于水印Awalys应用于奇数页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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