using System;
using System.Threading;
using System.Reflection;
using Word;public class MainClass
{
public static int Main (string[] argv)
{
//这相当于 CoCreateInstance 
Application app = new Application();  
//Application app1 = new Application();
//确保 Word 可见
app.Visible=true;
//设置以创建一个空的纯文本文档
// 将这些变量设置为 Missing.Value 可视为向
// 函数中传递空。这一点很有必要,因为引用不能
// 传递 C# 空。
object template=Missing.Value;
object newTemplate=Missing.Value;
object documentType=Missing.Value;
object visible=true;
_Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible); //Thread.Sleep (5000);  //显示空文档五秒钟
//doc.Words.Last.InsertBefore ("This document is no longer empty!"+"\r\n"); //doc.Words.Last.InsertBefore ("\r\n"); object LinkToFile=false;
object SaveWithDocument=true;
//object Range=Missing.Value;
object Range=Missing.Value;
doc.Words.First.InsertBefore ("This document is no longer empty1!");
// doc.Words.First.InsertBefore ("\r\n"); app.Selection.InlineShapes.AddPicture("E:\\工具\\编程工具\\网页素材\\图片\\MST36.jpg",ref LinkToFile,ref SaveWithDocument,ref Range)  ; doc.Words.First.InsertBefore ("This document is no longer empty2!");
doc.Words.First.InsertBefore ("\r\n");
app.Selection.InlineShapes.AddPicture("E:\\工具\\编程工具\\网页素材\\图片\\MST36.jpg",ref LinkToFile,ref SaveWithDocument,ref Range)  ;
doc.Words.First.InsertBefore ("This document is no longer empty1!");
doc.Words.First.InsertBefore ("\r\n");
//
// app.Selection.InlineShapes.Application.ActiveDocument.Words.Last.InsertBefore("fsdfsaf");
Thread.Sleep (5000);  //再等待五秒钟 //保存文件,并使用默认值(文件名除外)
object fileName = Environment.CurrentDirectory+"\\example2";
object optional = Missing.Value;
//#if OFFICEXP
        doc.SaveAs2000( ref fileName,
//#else
//doc.SaveAs ( ref fileName,
//#endif
ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional, ref optional); // 现在像好用户一样,使用 Quit 方法进行清理
object saveChanges = true;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
return 0;
}
}