将图片添加到word文档的页脚 [英] Adding picture to footer of a word document
本文介绍了将图片添加到word文档的页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序有问题.我需要在word文档的页脚中添加图片.
I have a problem with my program. I need to add a picture in the footer of a word document.
我有 2 个功能,替换书签文本和添加图像.替换书签文本有效.添加图像不起作用,我在 stackoverflow 上搜索了几天,但找不到任何解决方案.我希望有人可以帮助我.
I have 2 functions, replacing bookmarked text and add images. The replace bookmarked text works. add images doesnt work, i searched for days on stackoverflow, but i cant find any sollution. I hope someone can help me out.
private static void AddImages(Document wordDoc, string imagePath){
var sec = wordDoc.Application.Selection.Sections[1];
var ft = sec.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary];
var rngFooter = ft.Range;
object oRange = rngFooter;
var autoScaledInlineShape = ft.Shapes.AddPicture(imagePath);
var scaledWidth = autoScaledInlineShape.Width;
var scaledHeight = autoScaledInlineShape.Height;
autoScaledInlineShape.Delete();
// Create a new Shape and fill it with the picture
var newShape = wordDoc.Shapes.AddShape(1, 0, 0, scaledWidth, scaledHeight);
newShape.Fill.UserPicture(imagePath);
// Convert the Shape to an InlineShape and optional disable Border
var finalInlineShape = newShape.ConvertToInlineShape();
finalInlineShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
// Cut the range of the InlineShape to clipboard
finalInlineShape.Range.Cut();
// And paste it to the target Range
ft.Paste();
}
推荐答案
找到解决方案
private static void FindAndReplaceImages(Document wordDoc, string imagePath){
var sec = wordDoc.Application.Selection.Sections[1];
foreach (Section wordSection in wordDoc.Sections)
{
var footer = sec.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary];
var footerImage = footer.Shapes.AddShape(1, 0, 0, 594, 280);
footerImage.Fill.UserPicture(imagePath);
footerImage.WrapFormat.Type = WdWrapType.wdWrapThrough;
footerImage.WrapFormat.AllowOverlap = -1;
footerImage.WrapFormat.Side = WdWrapSideType.wdWrapBoth;
footerImage.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
footerImage.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
footerImage.Top = (float)561.2;
}
}
这篇关于将图片添加到word文档的页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文