我有一个.docx文件,页脚和标题中有图像。如何获取图像,知道哪个在页脚中,哪个在标题中?
我尝试使用:
Microsoft.Office.Interop.Word.Range range = section.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range;
但我看不到任何有用的属性。
答案 0 :(得分:2)
看一下Range对象的InlineShapes(http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.inlineshapes(v=office.11).aspx)属性。它是InlineShape(http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.inlineshape(v=office.11).aspx)对象的集合.Inline对象可以是几种类型的对象中的任何一种,而你可以通过访问Type属性(http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.inlineshape.type(v=office.11).aspx)
来检查它是哪一个(自从被问到这已经过去差不多2年了,我希望作者找到解决方案,我添加了这个以防万一其他人可能会觉得这很有帮助。)
答案 1 :(得分:0)
方式1:
foreach(Microsoft.Office.Interop.Word.Shape Headershape in OHeader.Shapes)
{
InlineShape inlineshape = Headershape.ConvertToInlineShape();
Range PictureRange = inlineshape.Range;
inlineshape.Delete();
PictureRange.InlineShapes.AddPicture(m_sLogoPath);
}
方式:2
foreach (InlineShape shape in OHeader.Range.InlineShapes)
{
if (shape.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapePicture)
{
shape.Delete();
oSection.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.InlineShapes.AddPicture(m_sLogoPath);
}
}
答案 2 :(得分:0)
var applicationWord = new Microsoft.Office.Interop.Word.Application();
adoc = applicationWord.Documents.Open(ref ofileName);
foreach (Section oSection in adoc.Sections)
{
foreach (HeaderFooter OHeader in oSection.Headers)
{
foreach(Microsoft.Office.Interop.Word.Shape Headershape in OHeader.Shapes)
{
Headershape.Delete();
OHeader.Shapes.AddPicture(m_sLogoPath);
}
}
}