实例引用:http://www.7es.cn/Software_development/171.shtml

using Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;

#region 把Word文档装化为Html文件
/**//// <summary>
/// 把Word文档装化为Html文件
/// </summary>
/// <param name="strFileName">要转换的Word文档</param>
public static void WordToHtml( string strFileName )
{
string saveFileName = strFileName + DateTime.Now.ToString( "yyyy-MM-dd-HH-mm-ss" ) + ".html";
WordToHtml( strFileName, saveFileName );
}
/**//// <summary>
/// 把Word文档装化为Html文件
/// </summary>
/// <param name="strFileName">要转换的Word文档</param>
/// <param name="strSaveFileName">要生成的具体的Html页面</param>
public static void WordToHtml( string strFileName, string strSaveFileName )
{
Microsoft.Office.Interop.Word.ApplicationClass WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
Object oMissing = System.Reflection.Missing.Value;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object fileName = strFileName; WordDoc = WordApp.Documents.Open( ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing ); Type wordType = WordApp.GetType();
// 打开文件
Type docsType = WordApp.Documents.GetType();
// 转换格式,另存为
Type docType = WordDoc.GetType();
object saveFileName = strSaveFileName;
docType.InvokeMember( "SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML } ); #region 其它格式:
/**//**/
/**////wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
//-----------------------------------------------------------------------------------
// docType.InvokeMember( "SaveAs", System.Reflection.BindingFlags.InvokeMethod,
// null, WordDoc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML} );
// 退出 Word
//wordType.InvokeMember( "Quit", System.Reflection.BindingFlags.InvokeMethod,
// null, WordApp, null );
#endregion
WordDoc.Close( ref oMissing, ref oMissing, ref oMissing );
WordApp.Quit( ref oMissing, ref oMissing, ref oMissing );
}
#endregion

检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。

问题解决引用:

http://blog.163.com/wj_1251/blog/static/1502740252012910105027530/

https://jingyan.baidu.com/article/7e440953d666702fc0e2eff7.html

配置网站web.config,指定用户访问

配置服务器上word组件,增加web.config配置用户的操作权限。注:标识使用交互式用户,不然WordApp.Documents.Open时,返回空对象

c#操作word类,进行html和word文档的互相转换的更多相关文章

  1. Java使用Aspose组件进行多文档间的转换操作

    首先,祝大家新年快乐,2019诸事顺利,很久没有更新博客,今天要给大家说的是 ”Aspose“ 组件,作为2019年第一篇博客,希望大家能够多多支持,2019年要继续加油. 什么是Aspose? As ...

  2. 如何快速访问MSDN某一个类或方法的帮助文档

    如何快速访问MSDN某一个类或方法的帮助文档? 我一般都是在Google上搜索的如"string msdn",而不是在Msdn上直接查找(你不可能知道所有的类或方法的完整命名空间) ...

  3. org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException 前言中不允许有内容 来自类路径资源的XML文档中的第1行是无效的

    今天复习一下Spring和Hibernate的整合,遇到了一个问题,报错信息如下: org.springframework.beans.factory.xml.XmlBeanDefinitionSto ...

  4. Linux系统下Java 转换Word到PDF时,结果文档内容乱码的解决方法

    本文分享在Linux系统下,通过Java 程序代码将Word转为PDF文档时,结果文档内容出现乱码该如何解决.具体可参考如下内容: 1.问题出现的背景 在Windows系统中,使用Spire.Doc ...

  5. word每次打开都要选择文档类型

    每次打开word07 都出现下面一个框框,说要转换文件. 在Word2013文档中,为了能更好地使用“从任意文件还原文本”功能,用户需要启用“打开时确认文件格式转换”功能,以在打开并恢复文件时出现文件 ...

  6. jQuery对标签、类样式、值、文档、DOM对象的操作

    jquery的标签属性操作 使用attr()方法对html标签属性进行操作,attr如果参数是一个参数,表示获取html标签的属性值,如果是两个参数则是设置标签属性名以及对象的属性值 .prop()适 ...

  7. 1、关于python第三方工具操作xls和xlsx格式的excel文档选型的吐血经历

    首先,最近看了python的一本书,其中第7章是关于文章操作的,就计划把python操作excel,word,txt,xml,html,json等格式的文档做个总结,并实现一些功能,但是,第一步就要把 ...

  8. python 全栈开发,Day54(jQuery的属性操作,使用jQuery操作input的value值,jQuery的文档操作)

    昨日内容回顾 jQuery 宗旨:write less do more 就是js的库,它是javascript的基础上封装的一个框架 在前端中,一个js文件就是一个模块 一.用法: 1.引入包 2.入 ...

  9. 008-elasticsearch5.4.3【二】ES使用、ES客户端、索引操作【增加、删除】、文档操作【crud】

    一.ES使用,以及客户端 1.pom引用 <dependency> <groupId>org.elasticsearch.client</groupId> < ...

随机推荐

  1. as3设计模式乱用之工厂模式

    好久没写技术相关的日记了,一忙,二懒,三则被这单调的生活熏得没什么感悟. 其实这篇日记早就想写了,项目开发初期的时候,带学生.经常看到那种乱用设计模式的现象.一方面,公司面试人的时候喜欢问设计模式,另 ...

  2. Logstash详解之——input模块

    原文地址 Logstash由三个组件构造成,分别是input.filter以及output.我们可以吧Logstash三个组件的工作流理解为:input收集数据,filter处理数据,output输出 ...

  3. hl7 V2中Message Control ID的含义及应用

    HL7 v2中的MSH,MSA段都有Message Control ID. 有几点需要注意: 1.所有的MessageControlID必须唯一 2.对于MSH中的MessageControlID, ...

  4. hihoCoder#1121(二分图判定)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Nettle,从这个星期开始由我来完成我们的Weekly. 新年回家,又到了一年一度大龄 ...

  5. Cortex-M0(+)内核的处理器架构简介

    Cortex-M0(+)内核的处理器架构简介 2015年03月02日 16:51:12 阅读数:3158 系统架构 Cortex-M0处理器具有32位系统总线接口,以及32位地址线,即有4GB的地址空 ...

  6. HashSet中是如何判断元素是否重复的

    HashSet不能添加重复的元素,当调用add(Object)方法时候, 首先会调用Object的hashCode方法判hashCode是否已经存在,如不存在则直接插入元素: 如果已存在则调用Obje ...

  7. appium_python-测试报告模板话化

    我们用python拓展模板 HTMLTestRunner.py python3 要自己重新改写下输出输入接口,可直接下载 改好的 地址 链接:http://pan.baidu.com/s/1hsOBw ...

  8. “百度杯”CTF比赛 九月场

    Test: 题目提示查资料 打开地址,是一个海洋cms 海洋cms有个前台getshell的漏洞 在地址后加上/search.php?searchtype=5&tid=&area=ev ...

  9. leetcode657

    bool judgeCircle(string moves) { ;//垂直位移 ;//水平位移 for (auto m : moves) { if (m == 'U') { V++; } else ...

  10. leetcode398

    public class Solution { int[] nums; Random rnd; public Solution(int[] nums) { this.nums = nums; this ...