Vsto形状可见性

时间:2018-01-27 17:43:28

标签: c# vsto word-addins

使用以下代码我切换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
}

1 个答案:

答案 0 :(得分:1)

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

直到最近,才能将内联格式应用于Shape对象。你有InlineShapes和Shapes,而InlineShapes没有Visible属性,因为Word像文本一样处理它们。这仍然适用于具有换行格式"内联"。

的Shape

你必须应用" Hidden"字体格式化为格式化的图形"内联"。

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
}
}
相关问题