62,074
社区成员
发帖
与我相关
我的任务
分享
string message = "";
try
{
//打开文档:
string name = "新建 Microsoft Word 文档.doc";
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"E:\\新建 Microsoft Word 文档.doc ";
oDoc = oWord.Documents.Open(ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//插入图片
string PName = @"E:\\360截图20110815162932593.jpg";//图片所在路径
object LinkToFile = false;
object SaveWithDocument = true;
object Anchor = oDoc.Application.Selection.Range;
oDoc.Application.ActiveDocument.InlineShapes.AddPicture(PName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
oDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;//图片宽度
oDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;//图片高度
//文件保存
object fileName2 = @"E:\\新建 Microsoft Word 文档2.doc ";
oDoc.SaveAs(ref fileName2, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
//oDoc.Quit(ref oMissing, ref oMissing, ref oMissing);
message = name + "文档生成成功,以保存到C:CNSI下";
}
catch
{
message = "文件导出异常!";
}
//return message;
oWord.GetType().InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);