用于网站上,上传 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的更多相关文章

  1. C#将Word转换成PDF方法总结(基于Office和WPS两种方案)

    有时候,我们需要在线上预览word文档,当然我们可以用NPOI抽出Word中的文字和表格,然后显示到网页上面,但是这样会丢失掉Word中原有的格式和图片.一个比较好的办法就是将word转换成pdf,然 ...

  2. 【文件】使用jacob将word转换成pdf格式

    使用jacob将word转换成pdf格式   1.需要安装word2007或以上版本,若安装07版本学确保该版本已安装2downbank0204MicrosoftSaveasPDF_ XPS,否则安装 ...

  3. word转换成HTML 以及IE不兼容问题

    public static bool WordToHtml(string wordFileName, string htmlFileName) { try { Object oMissing = Sy ...

  4. [JavaWeb基础] 025.JAVA把word转换成html

    用第三方插件POI把word文档转换成HTML,下面直接上代码 package com.babybus.sdteam.wordtopdf; import java.io.BufferedWriter; ...

  5. linux环境php将word转换成pdf

    原文地址:http://www.niu12.com/article/15 ubuntu.java环境.openoffice.jodConverter.php 1.安装java环境 a. jdk下载(我 ...

  6. JAVA:借用OpenOffice将上传的Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

  7. 如何将WORD表格转换成EXCEL表格

    WORD和EXCEL都可以制作表格,但WORD表格与EXCEL表格之间有着很明显的差距,所以在办公中经常会需要将WORD转换成EXCEL,今天小编就教大家一招将WORD表格转换成EXCEL表格. 操作 ...

  8. OpenOffice Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

  9. C#.net word excel powerpoint (ppt) 转换成 pdf 文件

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

随机推荐

  1. Codeforces Round #402 (Div. 2) A,B,C,D,E

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. python 正则匹配字符串里面的字符

    import re x=re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') print(x)

  3. 构建工具 Ant、Maven和Gradle

    构建工具的作用 依赖管理 测试,打包,发布 主流的构建工具 Ant:提供编译,测试,打包 Maven:在Ant的基础上提供了依赖管理和发布的功能 Gradle:在Maven的基础上使用Groovy管理 ...

  4. window下rabbitmq环境安装

    最近项目想用个MQ来做业务分离,看了市面上众多产品,最后选了rabbitmq,理由很简单,对window的支持很到位(其实是公司的系列产品都是.net的). 安装方法什么的就不说了,直接到官网下载双击 ...

  5. Android手机无线adb

    1.首先电脑,手机通过数据线链接电脑,然后通过adb devices 查看到已连接 2.输入:adb tcpip 5555 3.输入:adb connect 222.222.221.137:5555 ...

  6. HDU - 5917 水题

    题意:n个点m条边,找点集个数,点集满足有任意三个点成环,或者三个点互不相连 题解:暴力复杂度O(n^5/120*O(ok))==O(能过) //#pragma comment(linker, &qu ...

  7. ssh 上传文件以及文件夹到linux服务器

    闲来无事分享一篇,帮助到你的话,麻烦给老弟点个关注.经常会分享一些实用技能. 回归正题,现在服务器linux很多.是不是不会传文件?别急 下面就是方法: 一.上传文件到linux服务器 首先从你本地切 ...

  8. URAL 1106 Two Teams (DFS)

    题意 小组里有N个人,每个人都有一个或多个朋友在小组里.将小组分成两个队伍,每个队伍的任意一个成员都有至少一个朋友在另一个队伍. 思路 一开始觉得和前几天做过的一道2-sat(每个队伍任意两个成员都必 ...

  9. 虚函数不应该是inlined(More Effective C++ 笔记)

    在实际运行中,虚函数所需的代价与内联函数有关. 实际上虚函数不能是内联的. 这是因为“内联”是指“在编译期间用被调用的函数体本身来代替函数调用的指令,” 但是虚函数的“虚”是指“直到运行时才能知道要调 ...

  10. adb命令安装apk

    1.将需要安装的apk放在platform-tools下 2.将手机和电脑连接,在cmd中输入 adb devices查看 3.使用adb命令安装apk,在cmd中输入:adb install apk ...