润宇软件
首 页 企业简介 项目案例 软件定制 行业软件 解决方案 企业动态 服务专区 客服中心
业务介绍:西安软件公司、软件开发、软件定制、软件外包
软件 方案 文章
  润宇软件 >> 新闻资讯  >> 解决方案

asp.net 将word转换成html

发布时间:2016/6/25  浏览次数:21次  字体【    】

1.导入 Microsoft.Office.Interop.Word.dll文件

2.源代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->        /// <summary>
        /// word转成html
        /// </summary>
        /// <param name="wordFileName"></param>
        private string WordToHtml(object wordFileName)
        {
            //在此处放置用户代码以初始化页面
            Word.ApplicationClass word = new Word.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, WdSaveFormat.wdFormatFilteredHTML });

            docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod,
             null, doc, null);

            //退出 Word
            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
             null, word, null);

            return saveFileName.ToString();
        }

  关闭本页
西部IT网合作伙伴 合作伙伴
陕西省 | 榆林 | 延安 | 铜川 | 渭南 | 商洛 | 宝鸡 | 汉中 | 安康 | 咸阳
网站首页 | 关于我们 | 售后服务 | 项目合同 | 查看留言 | 在线留言 | 客服中心
© 版权所有:西安润宇软件科技有限公司 
公司地址:西安市丝路国际创意梦工厂4号楼 联系电话:029-87878512 手机:13468700578 联系人:李先生
Copyright ® 2009-2020 RunYusoft.com Inc. All Rights Reserved 
技术支持:西安润宇软件科技有限公司  陕ICP备11000720号