如何把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,& ...
随机推荐
- Winform XiaoCai.WinformUI 框架界面设计
开源用户界面和布局的套件XiaoCai.WinformUI(美化用户界面利器) http://www.cnblogs.com/aganqin/p/3400453.html 源码下载:https://g ...
- 使用VS连接SQLServe时提示未能载入文件或程序集“System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKey
解决方法: 就是去微软主页下载两个Microsoft SQL Server 2012补丁包,SQLSysClrTypes.msi和SharedManagementObjects.msi ...
- 【转】SoapUI5.0创建WebService接口模拟服务端
原文:http://blog.csdn.net/a19881029/article/details/26348627 使用SoapUI创建WebService接口模拟服务端需要接口描述文件 MathU ...
- SaundProgressBar
https://github.com/eltld/SaundProgressBar
- [AnuglarJS] TweenMax with ngAnimate
Also read: http://www.cnblogs.com/Answer1215/p/3941966.html Using ngAnimate: //!annotate="YourA ...
- [AngularJS] Accessing Services from Console
Using the Chrome console, you can access your AngularJS injectable services. This is down and dirty ...
- 终端I/O之获得和设置终端属性
使用函数tcgetattr和tcsetattr可以获得或设置termios结构.这样也可以检测和修改各种终端选择标志和特殊字符,以使终端按我们所希望的方式进程操作. #include <term ...
- SQL Server 的事务和锁(一)
最近在项目中进行压力测试遇到了数据库的死锁问题,简言之,如下的代码在 SERIALIZABLE 隔离级别造成了死锁: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 SELECT @ ...
- AngularJS特性
如果你不熟悉什么是Angular.js的话,小编我强烈推荐你阅读 Javascript教程:AngularJS的五个超酷特性.简单来说Angular.js是google开发者设计和开发的一套前端开发框 ...
- JavaScript中数组操作
var arr1=new Array(); arr1.push(1);//在数组的中末尾添加元素,并返回新的长度 arr1.push(2);//在数组的中末尾添加元素,并返回新的长度 arr1.pop ...