[转]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 ...
随机推荐
- 操作数据库的时候,使用自带的DbProviderFactory类 (涉及抽象工厂和工厂方法)
微软自带的DbProviderFactory https://msdn.microsoft.com/en-us/library/system.data.common.dbproviderfactory ...
- Redis之Sorted Set 有序集合
Redis Sorted Set 有序集合 Redis 有序集合和集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过分 ...
- The Road to Ryu: Hi Ryu
参考: ryu入门教程 ryu ryu/ryu Structure -ryu/ryu app base cmd contrib controller lib ofproto services test ...
- C++总结:C++中的const和constexpr
C++中的const可用于修饰变量.函数,且在不同的地方有着不同的含义,现总结如下. const的语义 C++中的const的目的是通过编译器来保证对象的常量性,强制编译器将所有可能违背const对象 ...
- c++指向指针的指针与 c++指针作为函数参数传递问题
一直搞不明白,c++中指针到底是个啥东西,今天遇到到c++,指向指针的指针的问题,突然有点开窍了. 举个例子: int main(int argc, char** argv){ int a[5]={1 ...
- 何时使用MQ ?
何时使用MQmq作为一种基础中间件在互联网项目中有着大量的使用. 一种技术的产生自然是为了解决某种需求,通常来说是以下场景: 需要跨进程通信:B系统需要A系统的输出作为输入参数.当A系统的输出能力远远 ...
- Rails 5 Test Prescriptions 第8章 Integration Testing with Capybara and Cucumber
Capybara: A complete reference is available atrubydoc.info. 集成测试就是把局部的程序组合起来测试. 端到端测试是一个特殊的集成测试,覆盖了 ...
- HDU 1045 dfs + 回溯
题目链接:http://acm.hrbust.edu.cn/vj/index.php?/vj/index.php?c=&c=contest-contest&cid=134#proble ...
- 设置Shader关键字高亮(网上转)
原文链接:http://www.cnblogs.com/cg_ghost/archive/2011/11/30/2268734.html 经过试验,在VS2012有效. 1. 创建或编辑usertyp ...
- react 拖拽排序---原生
定义css, 两个动画 .drag-up { -webkit-animation: dragup ease 0.2s 1; animation: dragup ease 0.2s 1; -webkit ...