用于网站上,上传 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. [调参]CV炼丹技巧/经验

    转自:https://www.zhihu.com/question/25097993 我和@杨军类似, 也是半路出家. 现在的工作内容主要就是使用CNN做CV任务. 干调参这种活也有两年时间了. 我的 ...

  2. LA 2963 超级传输(扫描)

    https://vjudge.net/problem/UVALive-2963 题意:需要在n个星球上各装一个广播装置,作用范围均为R.每个星球广播A类节目或者B类节目.a表示星球i收听到的和自己广播 ...

  3. BZOJ 2876 【NOI2012】 骑行川藏

    题目链接:骑行川藏 听说这道题需要一些高数知识 于是膜了一发dalao的题解……然后就没了…… 不要吐槽我的精度TAT……eps设太小了就TLE,大了就Wa……我二分的边界是对着数据卡的…… 下面贴代 ...

  4. ros service

    Server部分: #!/usr/bin/env python import sys import os import rospy #from beginner.srv import * from b ...

  5. 前端基础3:js篇(基础及算法)

    1.js闭包相关: 题1: for (var i = 0; i < 5; i++) { setTimeout(function() { console.log(i); }, 1000 * i); ...

  6. vs警告 当前源代码跟内置的版本不一致解决办法

    本文转载于:http://blog.csdn.net/bull521/article/details/51334464 vs警告 当前源代码跟内置的版本不一致解决办法 1.删除掉 我的文档/visua ...

  7. voj 1754 spfa

    最优贸易 最优贸易 描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 ...

  8. UVALive-3989 Ladies' Choice (稳定婚姻问题)

    题目大意:稳定婚姻问题.... 题目分析:模板题. 代码如下: # include<iostream> # include<cstdio> # include<queue ...

  9. 直方图及low_value、high_value

    直方图 Histogram是一种特殊的列统计信息,详细描述了目标列的数据分布情况.存储在数据字典基表 histogram$; 专门为了准确评估分布不均匀的目标列的可选择率.结果集的cardianlit ...

  10. Ubuntu 分区方安

    方案一: / 40G/boot 200MBswap 1G-2G /home 20G 剩 下的分为几个独立的分区,不用指定挂载点,而是安装完成后修改 /etc/fstab ,将这些区挂载在/home的子 ...