[转]Aspose.Words.dll 将 Word 转换成 html
用于网站上,上传 Word 文档后显示文档内容(可看作在线阅读)。代码适用于 .net 2.0 或以上版本
(使用的未注册 Aspose.Words.dll 并尝试消除试用标志) 下载地址
string fileNameOut = string.Empty;
try {
using (OpenFileDialog fd = new OpenFileDialog()) {
fd.Filter = "Word 文档(*.doc,*.docx)|*.doc;*.docx|所有文件(*.*)|*.*";
if (fd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) {
fileNameOut = "D:\\html\\" + Path.GetFileNameWithoutExtension(fd.FileName) + ".html";
using (FileStream fs = new FileStream(fd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
var doc = new Document(fs);
var saveOptions = new HtmlSaveOptions();
saveOptions.SaveFormat = SaveFormat.Html;
saveOptions.ExportPageMargins = true;
doc.Save(fileNameOut, saveOptions);
}
}
}
}
catch (Exception ex) {
throw ex;
}
if (!string.IsNullOrEmpty(fileNameOut)) {
string fileText = File.ReadAllText(fileNameOut, Encoding.UTF8);
string moreText = "<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:justify; font-size:12pt\"><span style=\"font-family:'Times New Roman'; font-weight:bold; color:#ff0000\">还有部分内容未展示,请下载阅读。</span></p>";
string fileTextNew = Regex.Replace(fileText, "<p style=\".+?\"><span style=\".+?\">Evaluation Only. Created with Aspose.Words. Copyright 2003-2017 Aspose Pty Ltd.</span></p>", ""); File.WriteAllText(fileNameOut,
//fileText.Replace("<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:justify; widows:0; orphans:0; font-size:12pt\"><span style=\"font-family:'Times New Roman'; font-weight:bold; color:#ff0000\">Evaluation Only. Created with Aspose.Words. Copyright 2003-2017 Aspose Pty Ltd.</span></p>", "")
// .Replace("<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:justify; widows:0; orphans:0; font-size:12pt\"><span style=\"font-family:Calibri; font-weight:bold; color:#ff0000\">Evaluation Only. Created with Aspose.Words. Copyright 2003-2017 Aspose Pty Ltd.</span></p>", "")
fileTextNew.Replace("<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:justify; font-size:12pt\"><span style=\"font-family:'Times New Roman'; font-weight:bold; color:#ff0000\">This document was truncated here because it was created in the Evaluation Mode.</span></p>", moreText)
.Replace("<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:justify; widows:0; orphans:0; font-size:12pt\"><span style=\"font-family:'Times New Roman'; font-weight:bold; color:#ff0000\">This document was truncated here because it was created in the Evaluation Mode.</span></p>", moreText), Encoding.UTF8);
MessageBox.Show(this, "导出 html 成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Process.Start(fileNameOut);
}
仅供参考。如想表达感谢请扫以下二维码(支付宝 - 露)

[转]Aspose.Words.dll 将 Word 转换成 html的更多相关文章
- C#将Word转换成PDF方法总结(基于Office和WPS两种方案)
有时候,我们需要在线上预览word文档,当然我们可以用NPOI抽出Word中的文字和表格,然后显示到网页上面,但是这样会丢失掉Word中原有的格式和图片.一个比较好的办法就是将word转换成pdf,然 ...
- 【文件】使用jacob将word转换成pdf格式
使用jacob将word转换成pdf格式 1.需要安装word2007或以上版本,若安装07版本学确保该版本已安装2downbank0204MicrosoftSaveasPDF_ XPS,否则安装 ...
- word转换成HTML 以及IE不兼容问题
public static bool WordToHtml(string wordFileName, string htmlFileName) { try { Object oMissing = Sy ...
- [JavaWeb基础] 025.JAVA把word转换成html
用第三方插件POI把word文档转换成HTML,下面直接上代码 package com.babybus.sdteam.wordtopdf; import java.io.BufferedWriter; ...
- linux环境php将word转换成pdf
原文地址:http://www.niu12.com/article/15 ubuntu.java环境.openoffice.jodConverter.php 1.安装java环境 a. jdk下载(我 ...
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...
- 如何将WORD表格转换成EXCEL表格
WORD和EXCEL都可以制作表格,但WORD表格与EXCEL表格之间有着很明显的差距,所以在办公中经常会需要将WORD转换成EXCEL,今天小编就教大家一招将WORD表格转换成EXCEL表格. 操作 ...
- OpenOffice Word文档转换成Html格式
为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...
- C#.net word excel powerpoint (ppt) 转换成 pdf 文件
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
随机推荐
- Anaconda ubuntu16.04 Cuda 8.0安装pytorch
Pytorch 安装 Pytorch安装真的太让人省心了,在anaconda的环境下进行安装,只需要一个命令 具体命令请查看官网pytorch 找到适合你的版本进行安装 本机环境: anaconda3 ...
- 使用AspNetPager进行分页,查询条件丢失问题
在Asp.Net中使用AspNetPager进行分页时,发现一个问题: 当通过查询条件进行查询后,对查询结果进行翻页操作时,查询条件会丢失. 当修改UrlPaging属性后(设置UrlPaging=“ ...
- SCWS中文分词PHP扩展详细安装说明
因最近写的一段代码,需要用到中文分词,在网上找了一下,发现了scws这个不错的插件,故根据文档安装使用,下面记录下安装的全过程 系统:centos 安装scws wget http://www.xun ...
- fatal error LNK1112: 模块计算机类型“X86”与目标计算机类型“x64”冲突——我的解决方案
本文转载于:http://blog.csdn.net/tfy1028/article/details/8660823 win7 下,安装的VS2010,然后搭配opencv2.4.3运行,报错为:fa ...
- 水晶报表VS2010防止出现用户登录问题
1.联合查询,采用视图办法 2.借用如下语句 using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; ...
- oracle修改约束列
Oracle 增加修改删除字段 添加字段的语法:alter table tablename add (column datatype [default value][null/not null],-. ...
- 旋转木马幻灯片切换效果JS源码详解
首先,放上慕课网的课程链接,源码是在这个课程里分享出来的,https://www.imooc.com/learn/386. 文章适合学习过这个课程的同学,再看这篇文章,可能有更深入的理解.主要是对各种 ...
- Yii 入门
跳转到不同module Redirect to module after login Yii $this->redirect( array('/tradesman/default/index') ...
- w3m使用小记
By francis_hao Mar 8,2017 w3m是一个基于文本的web浏览器和分页器,运行在unix和windows系统上. 可显示包含链接的超文本标记语言(HTML),显示效果如 ...
- Linux运维学习笔记-网络安全等级保护
网络安全等级保护简介与作用: 验证信息系统是否满足相应安全保护等级的一个过程. 对不同信息系统分等级进行保护.