110,533
社区成员
发帖
与我相关
我的任务
分享
string saveFileName = DateTime.Now.ToString("yyyymmddhhmmss");
StringBuilder sb = new StringBuilder();
ApplicationClass appclass = new ApplicationClass();//实例化一个Word
Type wordtype = appclass.GetType();
Documents docs = appclass.Documents;//获取Document
Type docstype = docs.GetType();
object filename = Server.MapPath("a.doc");//Word文件的路径
Document doc = (Document)docstype.InvokeMember("Open", BindingFlags.InvokeMethod, null,
docs, new object[] { filename, true, true });//打开文件
StreamReader str = new StreamReader(filename.ToString(),Encoding.Default);
Type doctype = doc.GetType();
//觉得在这个地方应该有更好的操作。。。
object savefilename = Server.MapPath(saveFileName + ".html");//生成HTML的路径和名子
doctype.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc, new object[]
{ savefilename, WdSaveFormat.wdFormatHTML });//另存为Html格式
wordtype.InvokeMember("Quit", BindingFlags.InvokeMethod, null, appclass, null);//退出
Thread.Sleep(3000);//为了使退出完全,这里阻塞3秒