headfileName1 :图片完成路径
#region 打开Word并插入图片
object readOnly = false;
object isVisible = true;
object saveDocument = true;
object missing = System.Reflection.Missing.Value;
//打开Word
Word.ApplicationClass oWordApplic = null;
Word.Document oDoc = null;
try
{
try
{
oWordApplic = new Word.ApplicationClass();
if (oWordApplic == null)
MessageBox.Show("word为null");
oDoc = oWordApplic.Documents.Open(ref strDocFile, ref missing,ref readOnly,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible);//成功打开Word文件!
}
catch(Exception ex)
{
if (oWordApplic != null)
oWordApplic.Application.Quit(ref missing, ref missing, ref missing);
}
//插入图片
if (headfileName1 != "" && oDoc != null)
{
// "准备插入图片1!"
if (System.IO.File.Exists(headfileName1))
{
Word.Shape oShape1;
if (width1.ToString() != "" && width1.ToString() != "0")
{
if (height1.ToString() != "" && height1.ToString() != "0")
oShape1 = oDoc.Shapes.AddPicture(headfileName1,ref missing,ref saveDocument,ref left1,ref top1,ref width1,ref height1,ref missing);
else
oShape1 = oDoc.Shapes.AddPicture(headfileName1,ref missing,ref saveDocument,ref left1,ref top1,ref width1,ref missing,ref missing);
}
else
{
if (height1.ToString() != "" && height1.ToString() != "0")
oShape1 = oDoc.Shapes.AddPicture(headfileName1,ref missing,ref saveDocument,ref left1,ref top1,ref missing,ref height1,ref missing);
else
oShape1 = oDoc.Shapes.AddPicture(headfileName1,ref missing,ref saveDocument,ref left1,ref top1,ref missing,ref missing,ref missing);
}
oShape1.WrapFormat.Type = Word.WdWrapType.wdWrapNone;
oShape1.WrapFormat.AllowOverlap = 0;
}
}
//保存Word
if (oDoc != null)
{
oDoc.Save();
oDoc.Close(ref saveDocument,ref missing,ref missing);
}
#endregion