【问题标题】:Removing a Watermark from the Active document in VSTO Word 2013从 VSTO Word 2013 中的活动文档中删除水印
【发布时间】:2016-08-10 12:02:32
【问题描述】:

我正在尝试从文档中删除我之前在我的代码中创建的水印。以下是创建和应用水印的代码:

 foreach (Word.Section section in document.Sections)
        {
            nShape = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, tag, "Calibri", 10, MsoTriState.msoTrue, MsoTriState.msoFalse, 0, 0);
            nShape.Name = "securityTagWaterMark";
            nShape.Line.Visible = MsoTriState.msoFalse;
            nShape.Fill.Solid();
            nShape.Fill.ForeColor.RGB = (Int32)Word.WdColor.wdColorGray20;
            nShape.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
            nShape.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
            // bottom right location
            nShape.Left = (float)Word.WdShapePosition.wdShapeRight;
            nShape.Top = (float)Word.WdShapePosition.wdShapeBottom;
            nShape.LockAspectRatio = MsoTriState.msoTrue;
        }

如何检查文档以查找任何形状对象或替换页面上已有的水印文本。这是我尝试过的,但它不起作用:

 Word.Document currentDoc = Globals.ThisAddIn.Application.ActiveDocument;

        Word.Shapes shapeCollection = Globals.ThisAddIn.Application.ActiveDocument.Shapes;

        foreach (Word.Shape shape in shapeCollection)
        {
            if (shape.Name == "securityTagWaterMark")
            {
                shape.TextEffect.Text = newText;
            } 
        }

【问题讨论】:

    标签: vsto add-in office-addins word-2013 word-addins


    【解决方案1】:

    您将其添加到标题中,但在主要内容中寻找形状。 Word 不会返回 Document.Shapes 对象中的所有形状。这适用于标题中的对象,也适用于文档内容中存在的嵌套形状。

    Word.Document currentDoc = Globals.ThisAddIn.Application.ActiveDocument;
    Word.Shapes shapeCollection = Globals.ThisAddIn.Application.ActiveDocument.Shapes;
    foreach (Word.Shape shape in currentDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes)
    {
        if (shape.Name == "securityTagWaterMark")
        {
            shape.TextEffect.Text = newText;
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      • 2023-03-30
      相关资源
      最近更新 更多