问题描述
我有一个使用OpenXML处理的Word文件。除了图片内容控件之外,我什么都没有,并且我已成功将图片(“内容”)添加到该图片内容控件中。
现在一切都还不错,但是我对如何删除占位符图片一无所知。也就是说,我在插入的图片中间有那个“带有监视器,太阳和山的小图标”。您知道,当您插入图片内容控件时看到的图标。我可以通过VBA计算内容控件的数量,它说只有一个,因此彼此之间没有两个控件。
如果我删除目标内容控件(带有删除方法),则整个内容控件(包括正确设置的图片)都将被删除。
是否存在类似“ placeholderimage.Hide”的方法或应使用的方法?
DocumentFormat.OpenXml.Drawing.Blip blip = targetpicturecontrol.Descendants<DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault();
blip.Embed = mainPart.GetIdOfPart(imagePart);
解决方法
此代码隐藏(或删除)占位符
private static void RemovePlaceHolder(SdtProperties targetproperties)
{
Appearance appearance = new Appearance();
appearance.Val = new EnumValue<SdtAppearance>();
SdtAppearance sdtAppearance = new SdtAppearance();
sdtAppearance = SdtAppearance.Hidden;
appearance.Val.Value = sdtAppearance;
targetproperties.AppendChild(appearance);
}