实例引用: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. (转载)Windows: "net use" command introduction

    1)建立空连接: net use ""IP"ipc$ "" /user:"" (一定要注意:这一行命令中包含了3个空格) 2)建立 ...

  2. svn的ignor也是要提交的

    刚才一直奇怪为什么svn管理某个路径下总是报要提交,但是进入同步模式,看不到任何内容,就是告诉该文件夹要提交:后来才发现原来是我添加了一个该文件夹下的文件为svn:ignor,所以要提交以下.

  3. Spark Shuffle大揭秘

    什么是Shuffle: Shuffle中文翻译为“洗牌”,需要Shuffle的关键原因是某种具有共同特征的数据需要最终汇聚到一个计算节点上进行计算. Shuffle面临的问题: 1. 数据量非常大: ...

  4. @property_@synthesize 配套使用

    @property 类默认实现变量的get set方法 @synthesize 是指定那个变量的 get和set方法 eg: .h文件中定义 类Student中含有两个 int age,和int _a ...

  5. Spring Boot自定义配置与加载

    Spring Boot自定义配置与加载 application.properties主要用来配置数据库连接.日志相关配置等.除了这些配置内容之外,还可以自定义一些配置项,如: my.config.ms ...

  6. 删除pool error的解决方法

    标签(空格分隔): ceph,ceph运维,pool 问题描述: 删除pool的时候提示下面的错误: [root@node3 ~]# ceph osd pool delete ecpool ecpoo ...

  7. MySQL mysqldump 备份脚本(按照db.sql)

    mysqldump逻辑备份,按照db.sql文件区分,并压缩 #! /bin/bash #35 02 * * * mysql /data/mysqldata/scripts/mysqldump_per ...

  8. rails 自定义校验及validates_each多校验

    一.自定义校验 使用 validate 方法传入一个同名方法的 Symbol 即可. validate :my_validation private def my_validation if name ...

  9. 下拉框改变事件:获取下拉框中当前选择的文本 SelectionChanged事件

    /// <summary> /// 下拉框改变事件:获取下拉框中当前选择的文本 /// </summary> /// <param name="sender&q ...

  10. 第三章 Java内存模型(上)

    本章大致分为4部分: Java内存模型的基础:主要介绍内存模型相关的基本概念 Java内存模型中的顺序一致性:主要介绍重排序和顺序一致性内存模型 同步原语:主要介绍3个同步原语(synchroized ...