zoukankan      html  css  js  c++  java
  • word转换成html的方法

          之前用到了word转换成HTMl的做法,网上找过一段类似的代码,后发现好多不能执行,调试了半天才最终搞定。

           方法接参数是word文件路径。 执行这样的代码,需要添加 Microsoft.Office.Interop.Word.dll引用。

            /// <summary>
    /// Word转换为HTML
    /// </summary>
    /// <param name="path"></param>
    private string WordToHTMl(ref string path)
    {
    string pageUrl = null;

    object fltDocFormat = 10; //For filtered HTML Output
    object missing = System.Reflection.Missing.Value;
    object readOnly = false; //Open file in readOnly mode
    object isVisible = false;//The process has to be in invisible mode
    object fileName = path;

    //获取网站服务器端的路径
    string newPath = System.Web.HttpContext.Current.Server.MapPath("/ConvertFiles/");
    string newFileName = System.IO.Path.GetFileNameWithoutExtension(fileName.ToString());
    object saveFileName = newPath + savePath + newFileName + ".html";

    //判断文件是否被转换
    if (!System.IO.File.Exists(SaveFileName))
    {

    Microsoft.Office.Interop.Word.ApplicationClass objWord = new Microsoft.Office.Interop.Word.ApplicationClass();
    //打开word文档
    objWord.Documents.Open(ref fileName, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing, ref missing);
    //Do the background activity
    objWord.Visible = false;
    Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;

    oDoc.SaveAs(ref saveFileName, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
    oDoc.Close(ref missing, ref missing, ref missing);
    objWord.Quit(ref missing, ref missing, ref missing);
    //Process[] myProcesses = Process.GetProcessesByName("WINWORD");
    //foreach (Process myProcess in myProcesses)
    //{
    // myProcess.Kill();
    //}

    // string pageUrl = newFileName + ".html";
    // System.Web.HttpContext.Current.Server.Transfer(pageUrl);
    }

    else
    {
    //页面路径
    pageUrl = IpPath + FileName + ".html";

    }
    return pageUrl;


    }
  • 相关阅读:
    Qt 4套件的组成适用于Qt 4.5以后的版本
    GTK+, Qt, wxWidgets compare
    为什么选择Qt
    [转]零基础学Qt 4编程实例之四:理解并正确使用名字空间
    [转]Qt 4常见的IDE及其优缺点比较推荐Qt Creator和Eclipse
    *nix系统下验证Qt 4安装正确与否的方法和步骤
    Debian install matlab2010—also ok for ubuntu series!
    我推荐的Qt资源网站、论坛、博客等来自《零基础学Qt 4编程》一书的附录
    ubuntu debian fedora Mac install pgplot steps!!
    64位WIN7 配置IIS遇到问题
  • 原文地址:https://www.cnblogs.com/xiaoyao2011/p/2185125.html
Copyright © 2011-2022 走看看