如何把rtf、doc文件转换为HTML文件
//retText是路径
1 public string ExtractHtml(string rtfText)
{
try
{
//Create word object
Word.Application applicationObject = new Word.Application();
Type wordType = applicationObject.GetType(); //define path for save your temporary file.
string userTemp = @"F:\Code\DisplayPrintfile\DisplayPrintfile\file\";
//Open and save your rtf as HTML in your temp path.
object missing = Type.Missing;
object fileName = rtfText;
object False = false;
object rtfFileFormt = Word.WdSaveFormat.wdFormatRTF;
applicationObject.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone; Word.Document documentObject =applicationObject.Documents.Open(ref fileName, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref False, ref missing, ref missing,
ref missing, ref missing); object tempFileName =@"F:\Code\DisplayPrintfile\DisplayPrintfile\file\tempHtm.html";
object fileFormt = Word.WdSaveFormat.wdFormatHTML;
object makeFalse = false;
object makeTrue = true;
string absolutePath = tempFileName.ToString();
if (File.Exists(absolutePath))
{
try
{
File.Delete(absolutePath);
}
catch { }
} documentObject.SaveAs(ref tempFileName, ref fileFormt,
ref makeFalse, ref missing, ref makeFalse,
ref missing, ref missing, ref missing, ref makeFalse, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
GC.Collect();
GC.WaitForPendingFinalizers();
documentObject.Close(ref makeFalse, ref missing, ref missing);
GC.Collect();
GC.WaitForPendingFinalizers();
//File.Delete(rtfText); String htmlCode = ""; //Extract html source from the temporary html file.
if (File.Exists(absolutePath))
{
WebClient client = new WebClient();
htmlCode = client.DownloadString(absolutePath);
GC.Collect();
GC.WaitForPendingFinalizers();
try
{
File.Delete(absolutePath);
}
catch { }
} else
{
htmlCode = "";
} return htmlCode;
}
catch
{
return "";
}
}
如何把rtf、doc文件转换为HTML文件的更多相关文章
- Python如何实现doc文件转换为docx文件?
Python如何实现doc文件转换为docx文件? 在开发过程中遇到一个关于读写doc和docx的问题: 一个文件夹中有两种文件, 一种为doc结尾, 一种为docx结尾, 需要将这些文件全部重命名. ...
- 使用VirtualBox把IMG文件转换为VDI文件
使用VirtualBox把IMG文件转换为VDI文件 首先确保已安装VirtualBox. 需要使用的命令: 语法:$ VBoxManage convertdd input.img output.vd ...
- python之模块py_compile用法(将py文件转换为pyc文件)
# -*- coding: cp936 -*- #python 27 #xiaodeng #python之模块py_compile用法(将py文件转换为pyc文件):二进制文件,是由py文件经过编译后 ...
- APNS .p12文件转换为 .pem文件
1:先用mac的钥匙串工具,把APN的推送证书转换为 .p12文件: 2:在mac的终端下 把.p12文件转换为 .pem文件 openssl pkcs12 -in apns-dev-cert.p12 ...
- TensorFlow的checkpoint文件转换为pb文件
由于项目需要,需要将TensorFlow保存的模型从ckpt文件转换为pb文件. import os from tensorflow.python import pywrap_tensorflow f ...
- GIF文件转换为头文件工具
目的: GIF文件转为头文件 举例: 用UE打开GIF文件,如下图所示:图1 test.gif文件将上面文件内容转化为头文件,放到一个数组里面,内容如下:图2 test.h文件 思路: 从上面可知,将 ...
- bat文件转换为exe文件
批处理文件转换为exe文件(简单的处理文件),点击下载 使用超简单的了,不多说.
- 实战FFmpeg--iOS平台使用FFmpeg将视频文件转换为YUV文件
做播放器的开发这里面涉及的东西太多,我只能一步步往前走,慢慢深入.播放器播放视频采用的是渲染yuv文件.首先,要知道yuv文件是怎么转换得来的,其次,要知道怎么把视频文件保存为yuv文件.雷神的文章1 ...
- 将图片文件转换为.py文件
最近用wxpython写了一个脚本,其中要给窗体设置图标文件,需要单独的一个ico文件,这样就比较影响美观,另外打包的时候还要将图标文件一起打包很繁琐.这时候看到wxpython文件有一个工具img2 ...
- php如何将base64数据流文件转换为图片文件?
2017-03-07 在开发中,自己遇到一个前端在上传图片的时候,使用的base64数据流文件显示的图片. 也就是说 <img src="data:image/jpg;base64,& ...
随机推荐
- cocos2d-x android黑屏后返回游戏卡顿
转自:http://blog.csdn.net/wolfking_2009/article/details/8824931 2013年5月17日更新:对于之前说的资源释放问题,cocos2d-x 2. ...
- [转]iOS应用性能调优的25个建议和技巧
写在前面 本文来自iOS Tutorial Team 的 Marcelo Fabri,他是Movile的一名 iOS 程序员.这是他的个人网站:http://www.marcelofabri.com/ ...
- bzoj 2435: [Noi2011]道路修建 树上 dp
2435: [Noi2011]道路修建 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- html页面head区域的编码书写规范
今天我们简单的介绍一下head区域主要放置了内容.这里就不强调css和javascript了,这两者是大家所熟知的. head区一般必须加入的标识有: 公司版权注释 <!--- the site ...
- Citrix 服务器虚拟化之二十七 XenApp6.5发布服务器桌面
Citrix 服务器虚拟化之二十七 XenApp6.5发布服务器桌面 XenApp可发布以下类型的资源向用户提供信息访问,这些资源可在服务器或桌面上虚拟化: 1) 服务器桌面:发布场中服务器的整个 ...
- android之BitmapFactory.Options的使用
怎样获取图片的大小? 首先我们把这个图片转成Bitmap,然后再利用Bitmap的getWidth()和getHeight()方法就可以取到图片的宽高了. 新问题又来了,在通过BitmapFactor ...
- GIT GUI的使用(转)
前段时间跟着Ruby On Rails的toturial玩了一把Git,今天再回过头来,觉得这个版本控制工具真的很不错.下面来讲一下,在windows下如何通过git gui来管理代码. 首先,要在h ...
- boost.asio源码剖析
一. 前 言二. 架构浅析三. 流程分析 * 常见流程分析之一(Tcp异步连接) * 常见流程分析之二(Tcp异步接受连接) * 常见流程分析之三(Tcp异步读写数据) ...
- 使用jmeter对ActiveMQ集群性能方案进行评估--转载
原文地址:http://www.51testing.com/html/78/23978-143163.html 1.测试概要1.1 关于这篇文档中涉及的基于JMS的消息系统能为应用程序提供可靠的,高性 ...
- LeetCode32 Longest Valid Parentheses
题目: Given a string containing just the characters '(' and ')', find the length of the longest valid ...