word转html方法
在网上看了一篇关于word转html的文章,感觉不错,和大家分享一下。
/// <summary>
/// word转成html
/// </summary>
/// <param name="wordfilename">word文件路径</param>
private string ConvertWordToHtml(object wordfilename)
{
//在此处放置用户代码以初始化页面
word.ApplicationClass word = new word.ApplicationClass();
Type wordtype = word.GetType();
word.Documents docs = word.Documents;
//打开文件
Type docstype = docs.GetType();
word.Document doc = (word.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(, wordsavefilename.Length - ) + "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();
}
word转html方法
在此之前需要做一些准备工作
1、必须有office组件。
2、添加引用如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Interop.Word;
页面引用命名空间
3、项目添加Microsoft.Office.Interop.Word引用。
4、如果代码 word.ApplicationClass word = new word.ApplicationClass();提示无法嵌入互操作类型,则右键点击Microsoft.Office.Interop.Word组件选择属性,将嵌入互操作类型改为False即可解决问题。
完成之后,在word文件所在文件夹中会出现同名的html文件。但是有一个缺点,就是word排版格式不能保存。稍后改进。
word转html方法的更多相关文章
- aspose.word 使用简单方法
aspose.word使用简单方法 概念介绍 使用aspose生成word报表步骤: 加载word模板 提供数据源 填充 加载模板 提供了4种重载方法 1 2 3 4 5 public Documen ...
- 利用python批量修改word文件名的方法示例
利用python批量修改word文件名的方法示例 最近不小心把硬盘给格式化了,由于当时的文件没有备份,所以一下所有的文件都没有了,于是只能采取补救措施,用文件恢复软件恢复了一部分的数据出来,但是恢复完 ...
- aspose.word使用简单方法
概念介绍 使用aspose生成word报表步骤: 加载word模板 提供数据源 填充 加载模板 提供了4种重载方法 public Document(); public Document(Stream ...
- 如何将mysql表结构导出成Excel格式的(并带备注)另附转为word表格的方法
方法一: 1.使用一个MySQL管理工具:SQLyog,点击菜单栏“数据库”下拉的最后一项: 导出的格式如下: 2.要想转成Excel格式的只需手动将该表复制到Excel中去. 方法二: 1.以下用的 ...
- linux,centos,php,word转图片方法
刚开始的时候是客户的活儿,真的是没有想到,被这样一个方法给卡住了,真是醉了,经过漫长的一周,终于搞定了这个问题,以下就来给大家介绍以下这个方法把.能方便大家. (直接转换没办法,所以找了个折中的办法, ...
- Win2008服务启动不能调用Office Word的解决方法
本文为大家分享一下如何解决Windows Server 2008 服务启动不能调用Office Word的问题,分享这个教程的原因是,今天在Windows server2008上部署一个应用时发现了一 ...
- DCOM 找不到 office word 的解决方法
1. 在运行里面 输入 comexp.msc -32 2.在“DCOM配置”中,为IIS账号配置操作Word(其他Office对象也一样)的权限. 具体操作:“组件服务(Component ...
- AD17无法复制原理图到Word的解决方法
标题: 解决AD17无法复制原理图到WORD 作者: 梦幻之心星 347369787@QQ.com 标签: [AD, Word, 原理图] 目录: 软件 日期: 2019-3-17 目录 前提说明: ...
- GloVe:另一种Word Embedding方法
若想深层地理解GloVe和本文,最好了解SVD, word2vec(skip-gram为主)的相关知识.若仅寻求一种新的word embedding方法,可以不必了解以上前置知识. 一言以蔽之,Glo ...
随机推荐
- GO语言练习:网络编程 TCP 示例
1.代码 2.编译及运行 1.网络编程 TCP 示例 simplehttp.go 代码 package main import ( "net" "os" &qu ...
- GO语言练习:struct基础练习
1.代码 2.运行 1.代码 package main import "fmt" type Rect struct { x, y float64 width, height flo ...
- 一个简单的零配置命令行HTTP服务器 - http-server (nodeJs)
http-server 是一个简单的零配置命令行HTTP服务器, 基于 nodeJs. 如果你不想重复的写 nodeJs 的 web-server.js, 则可以使用这个. 安装 (全局安装加 -g) ...
- Oracle函数解析
一:大小写控制函数 lower()函数:(此函数将全部的大写字母都可以变为小写字母) upper()函数:(将输入的字符串变为大写字母) initcap()函数:(将每个字符串的首字母大写) 二:字 ...
- [LintCode] Count and Say 计数和读法
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...
- WinForm timer控件
timer 控件:按用户定义的时间间隔引发的事件 属性: Enabled 是否启用: Interval 事件发生的事件间隔,单位是毫秒 事件只有一个:Tick 事件经过指定的时间间隔 ...
- java web(一) 使用sql标签库+tomcat+mysql手动创建一个jsp练习总结
2016-09-0111:06:53 使用sql标签库+tomcat+mysql手动创建一个jsp 1. 1.1安装tomcat ...
- 用一段JS代码来比较各浏览器的极限内存与运算速度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- tab左右箭头切换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 安装repcached,并且测试其双向复制是否成功
备注:本实验不仅包括了repcached,还包括了memcache的配置安装 1.1实验环境. 1.2环境准备. 1.3配置一个memcache. 1.3.1安装memcache. 1.3.2启动me ...