+ -
当前位置:首页 → 问答吧 → 上传word并把word转换为html

上传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;
  }
  }

作者: weishao1223   发布时间: 2010-08-26

希望知道原因大哥,尽快给我回复。

作者: weishao1223   发布时间: 2010-08-26

服务器上根本没有安装Office(Word),需要安装才行!

作者: archu   发布时间: 2010-08-26