//将Word转换为htmlpublic string Wordtohtml(system.web.UI.htmlcontrols.htmlinputfile Wordfilepath){Microsoft.Office.interop.Word.applicationclass Word = new Microsoft.Office.interop.Word.applicationclass();type Wordtype = Word.gettype();Microsoft.Office.interop.Word.documents doCS = Word.documents; // 打开文件type doCStype = doCS.gettype(); //应当先把文件上传至服务器然后再解析文件为html//if (Wordfilepath.postedfile != null)//{ //变换前路径 改动1//string filepath = viewstate["sss"].tostring();//} string filepath = file1.postedfile.filename;object filename = filepath; Microsoft.Office.interop.Word.document doc = (Microsoft.Office.interop.Word.document)doCStype.invokemember("open",system.reflection.bindingflags.invokemethod, null, doCS, new object[]{ filename, true, true }); // 转换格式,另存为htmltype doctype = doc.gettype();string filename = system.datetime.now.year.tostring() + system.datetime.now.month.tostring() + system.datetime.now.day.tostring() +system.datetime.now.hour.tostring() + system.datetime.now.minute.tostring() + system.datetime.now.second.tostring(); //被转换的html文档保存的位置string configpath = appdomAIn.currentdomAIn.basedirectory.tostring() + "uploadfiles \\Wordtmp\\" + filename + ".html";object savefilename = configpath; doctype.invokemember("saveas", system.reflection.bindingflags.invokemethod,null, doc, new object[]{ savefilename, Microsoft.Office.interop.Word.wdsaveFormat.wdFormatfilteredhtml }); // 退出 WordWordtype.invokemember("qUIt", system.reflection.bindingflags.invokemethod, null, Word, null);//转到新生成的页面
打开Word文档,单击菜单栏中的“文件”,找到“另存为” 或“另存为网页”,如图所示。
击另存为” 或“另存为网页”,弹出"另存为" 窗口, 如图所示。
在"另存为" 窗口的“保存类型”,下拉菜单中找到“网页”。
在“文件名”一栏中可以修改我们想要的文件名。
点“保存”,就把一篇Word文档保存成网页格式了。
这时候在桌面就可以找到保存的网页,然后用浏览器会打开并显示网页的内容。