Word文档多种背景
我有一个包含 3 个页面部分的文件“test.docx”,每个部分都与上一页取消链接。现在我希望能够为每个部分设置不同的背景/水印。我只是不知道如何选择其他两个部分(或者..不是第一个部分)。
我这样尝试:
Application nWord = new Application();
object oMissing = System.Reflection.Missing.Value;
object fileName = @"E:\test.docx";
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);
Shape nShape = null;
for (int i = 0; i < nDoc.Sections.Count; i++)
{
nShape =
nDoc.Sections[i].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
"TEXT" + i.ToString(), "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)WdColor.wdColorGray20;
nShape.RelativeHorizontalPosition =
WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
nShape.RelativeVerticalPosition =
WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
nShape.Left = (float)WdShapePosition.wdShapeCenter;
nShape.Top = (float)WdShapePosition.wdShapeCenter;
}
nWord.Visible = true;
但它只是删除了第一部分的所有 3 个水印。
有什么想法吗?
I have a file "test.docx" with 3 page sections, and each section is unlinked from the previous page. Now I want to be able to set a different background/watermark for each section. I just don't know how to select the other 2 sections (or.. not the first one).
I tried it like this:
Application nWord = new Application();
object oMissing = System.Reflection.Missing.Value;
object fileName = @"E:\test.docx";
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);
Shape nShape = null;
for (int i = 0; i < nDoc.Sections.Count; i++)
{
nShape =
nDoc.Sections[i].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
"TEXT" + i.ToString(), "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)WdColor.wdColorGray20;
nShape.RelativeHorizontalPosition =
WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
nShape.RelativeVerticalPosition =
WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
nShape.Left = (float)WdShapePosition.wdShapeCenter;
nShape.Top = (float)WdShapePosition.wdShapeCenter;
}
nWord.Visible = true;
but it just drops all 3 watermarks on the first section.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WtFudgeE
如果将所有水印放在同一位置,则可能存在这些部分链接的可能性。一种检查方法是打开 Word 文档并执行以下操作:
打开页眉和页脚选项卡,然后在选项中,转到页眉和布局并选择“不同的首页”。
完成后,现在测试您的代码。 :)
您使用的 MS Word 版本是什么?也许,我可以发布相关快照?
WtFudgE
If it is dropping all water marks in same place then there could be a possibility that the sections are linked. One way to check would be to open the Word document and do the following
Open the Headers and Footers Tabs and in the Options, go to the Headers and Layouts and select "Different First Page"
Once you have done that now test your code. :)
What MS Word Version are you using? Maybe, I can post a relevant snapshot?
经过三天的搜索和讨论,我实际上找到了解决办法。这是我的解决方案:
I actually found a work around, after 3 days of searching and discussing. Here's my solution: