【问题标题】:Vsto Shape visibilityVsto 形状可见性
【发布时间】:2018-01-27 17:43:28
【问题描述】:

使用下面的代码,我在 word 文档中切换形状的可见性。当环绕格式设置为 wdWrapInline 时,形状仍然可见。澄清 Visible 属性正确设置为 false 但形状在文档中仍然可见。使用任何其他包装格式,形状可见性都会正确切换。知道为什么它不能与 wdWrapInline 一起使用吗?

Word.Application wordApplication = Globals.ThisAddIn.Application;
Word.Document document = wordApplication.ActiveDocument;
Word.Shapes shapes = document.Shapes;
foreach (Word.Shape shape in shapes)
{
    // If shape.WrapFormat.Type = Word.WdWrapType.wdWrapInline 
    // Then the Visible is set to false but it is still visible in the document
    shape.Visible == MsoTriState.msoFalse? MsoTriState.msoTrue : MsoTriState.msoFalse
}

【问题讨论】:

    标签: c# vsto word-addins


    【解决方案1】:

    它不适用于 Inline,因为 Inline 没有该属性。听起来有点疯狂,但是……

    直到最近,还无法将内联格式应用于 Shape 对象。您有 InlineShapes 和 Shapes,而 InlineShapes 没有 Visible 属性,因为 Word 像处理文本一样处理它们。这仍然适用于换行格式为“Inline”的 Shape。

    您必须将“隐藏”字体格式应用于“内联”格式的图形。

    foreach (Word.Shape shape in shapes)
    {
    // If shape.WrapFormat.Type = Word.WdWrapType.wdWrapInline 
    // Then the Visible is set to false but it is still visible in the document
    //You have to format it as a text character:
    if (shape.WrapFormat.Type == Word.WdWrapType.wdWrapInline)
    {
      shape.Anchor.Font.Hidden = true;
    }
    else
    {
      shape.Visible == MsoTriState.msoFalse? MsoTriState.msoTrue : MsoTriState.msoFalse
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多