C#将word转化为html时提示正由另一word进程使用
以下代码在本地运行没有问题,挂到iis上,远程访问就出现提示“正由另一word进程使用。。。。”的问题,请问是代码问题吗?如何修改啊?添加 GC.Collect();也没用啊。急~谢谢
ApplicationClass word = new ApplicationClass();
Type wordType = word.GetType();
Documents docs = word.Documents;
//打开文件
Type docsType = docs.GetType();
Document doc = (Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true });
//转换格式,另存为
Type docType = doc.GetType();
string wordSaveFileName = wordFileName.ToString();
string strSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.Length - 3) + "html";
object saveFileName = (object)strSaveFileName;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML});
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatFilteredHTML });
docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod,
null, doc, null);
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
return saveFileName.ToString();
ApplicationClass word = new ApplicationClass();
Type wordType = word.GetType();
Documents docs = word.Documents;
//打开文件
Type docsType = docs.GetType();
Document doc = (Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true });
//转换格式,另存为
Type docType = doc.GetType();
string wordSaveFileName = wordFileName.ToString();
string strSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.Length - 3) + "html";
object saveFileName = (object)strSaveFileName;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML});
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatFilteredHTML });
docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod,
null, doc, null);
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
return saveFileName.ToString();
...全文
相关推荐
C# HtmlToWord 将HTML文件转换成word文档
批量的把html 文件转换成word,不需要电脑上有word软件!并且支持本地图片,html链接的图片必须在本地,可以把图片转换到word里!
C# CHtmlToWord 将HTML文件转换成word文档!
批量的把html 文件转换成word,不需要电脑上有word软件!并且支持本地图片,html链接的图片必须在本地,可以把图片转换到word里! 代码简单,没有注释! 不喜勿喷!
C#读取word并转为html格式
C#代码启动word软件读取word文档全文,并另存为HTML文件格式,最后关闭软件。
C#NET实现Word转化为Html文件
代码简单易懂,整理的最有效的实现方式,有问题请联系
c#调用openxml组件对html与word进行互相转换
c#语言使用open xml 组件对html与word之间的相互转换,开源组件,效果不错,初学者可以参考


