上传word并把word转换为html
时间:2010-08-26
来源:互联网
上传word并把word转换为html
在本地浏览好好的(没有装IIS),即可以上传word,也可以把word转换为html,也可以浏览html
上传到服务器后,可以成功上传word,但浏览html的时候出错了,也就是Word转换为html失败,失败原因:检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80040154。
以下是word转换为html的方法及保存路径
public static string FormartDocToHtml(string DocSrc,string SaveSrc,string HtmlName)
{
string returnsrc = SaveSrc+"/"+HtmlName;
System.IO.FileInfo file = new System.IO.FileInfo(HttpContext.Current.Server.MapPath(DocSrc));
if (!file.Exists)
{
return "false";
}
else
{
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();
string filePath = System.Web.HttpContext.Current.Server.MapPath(DocSrc);
if (!System.IO.Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(SaveSrc)))
{
System.IO.Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(SaveSrc));
}
SaveSrc = System.Web.HttpContext.Current.Server.MapPath(SaveSrc);
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 });
// 转换格式,另存为html
Type docType = doc.GetType();
//被转换的html文档保存的位置
//string ConfigPath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "临时周报\\" + filename + ".html";
string ConfigPath = SaveSrc + "\\" + HtmlName;
object saveFileName = ConfigPath;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });
//// 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
return returnsrc;
}
}
在本地浏览好好的(没有装IIS),即可以上传word,也可以把word转换为html,也可以浏览html
上传到服务器后,可以成功上传word,但浏览html的时候出错了,也就是Word转换为html失败,失败原因:检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80040154。
以下是word转换为html的方法及保存路径
public static string FormartDocToHtml(string DocSrc,string SaveSrc,string HtmlName)
{
string returnsrc = SaveSrc+"/"+HtmlName;
System.IO.FileInfo file = new System.IO.FileInfo(HttpContext.Current.Server.MapPath(DocSrc));
if (!file.Exists)
{
return "false";
}
else
{
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();
string filePath = System.Web.HttpContext.Current.Server.MapPath(DocSrc);
if (!System.IO.Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(SaveSrc)))
{
System.IO.Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(SaveSrc));
}
SaveSrc = System.Web.HttpContext.Current.Server.MapPath(SaveSrc);
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 });
// 转换格式,另存为html
Type docType = doc.GetType();
//被转换的html文档保存的位置
//string ConfigPath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "临时周报\\" + filename + ".html";
string ConfigPath = SaveSrc + "\\" + HtmlName;
object saveFileName = ConfigPath;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });
//// 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
return returnsrc;
}
}
作者: weishao1223 发布时间: 2010-08-26
希望知道原因大哥,尽快给我回复。
作者: weishao1223 发布时间: 2010-08-26
服务器上根本没有安装Office(Word),需要安装才行!
作者: archu 发布时间: 2010-08-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28