代码如下:
object range = wordDoc.Paragraphs.Last.Range;
object linkToFile = false; //默认
object saveWithDocument = true; //默认
string dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
InlineShape inlineShape = wordDoc.InlineShapes.AddPicture(dir + "\\test.jpg", ref linkToFile, ref saveWithDocument, ref range);//向文档中插入图片
if (inlineShape.Height >= 300)
{
inlineShape.Width = inlineShape.Width * 300 / inlineShape.Height;
inlineShape.Height = 300;
}
if (inlineShape.Width >= 300)
{
inlineShape.Height = inlineShape.Height * 300 / inlineShape.Width;
inlineShape.Width = 300;
}
//Shape cShape = inlineShape.ConvertToShape();
inlineShape.ConvertToShape().WrapFormat.Type = WdWrapType.wdWrapInline;//设置嵌入型
//cShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
//cShape.WrapFormat.Type = WdWrapType.wdWrapInline;
wordApp.Selection.Text = "";
wordApp.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevelBodyText;
wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
wordApp.Selection.EndKey(6, 0);
wordApp.Selection.Font.Name = "仿宋_GB2312";
wordApp.Selection.Font.Name = "Times New Roman";
wordApp.Selection.Font.Size = 16;
wordApp.Selection.ParagraphFormat.LineSpacing = 18F;
wordApp.Selection.Text = "\n";
有没有大神解释一下,主要是嵌入型格式设置失败,word大版本都是2010版。