//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 "";
}
}

demo: 下载

如何把rtf、doc文件转换为HTML文件的更多相关文章

  1. Python如何实现doc文件转换为docx文件?

    Python如何实现doc文件转换为docx文件? 在开发过程中遇到一个关于读写doc和docx的问题: 一个文件夹中有两种文件, 一种为doc结尾, 一种为docx结尾, 需要将这些文件全部重命名. ...

  2. 使用VirtualBox把IMG文件转换为VDI文件

    使用VirtualBox把IMG文件转换为VDI文件 首先确保已安装VirtualBox. 需要使用的命令: 语法:$ VBoxManage convertdd input.img output.vd ...

  3. python之模块py_compile用法(将py文件转换为pyc文件)

    # -*- coding: cp936 -*- #python 27 #xiaodeng #python之模块py_compile用法(将py文件转换为pyc文件):二进制文件,是由py文件经过编译后 ...

  4. APNS .p12文件转换为 .pem文件

    1:先用mac的钥匙串工具,把APN的推送证书转换为 .p12文件: 2:在mac的终端下 把.p12文件转换为 .pem文件 openssl pkcs12 -in apns-dev-cert.p12 ...

  5. TensorFlow的checkpoint文件转换为pb文件

    由于项目需要,需要将TensorFlow保存的模型从ckpt文件转换为pb文件. import os from tensorflow.python import pywrap_tensorflow f ...

  6. GIF文件转换为头文件工具

    目的: GIF文件转为头文件 举例: 用UE打开GIF文件,如下图所示:图1 test.gif文件将上面文件内容转化为头文件,放到一个数组里面,内容如下:图2 test.h文件 思路: 从上面可知,将 ...

  7. bat文件转换为exe文件

    批处理文件转换为exe文件(简单的处理文件),点击下载 使用超简单的了,不多说.

  8. 实战FFmpeg--iOS平台使用FFmpeg将视频文件转换为YUV文件

    做播放器的开发这里面涉及的东西太多,我只能一步步往前走,慢慢深入.播放器播放视频采用的是渲染yuv文件.首先,要知道yuv文件是怎么转换得来的,其次,要知道怎么把视频文件保存为yuv文件.雷神的文章1 ...

  9. 将图片文件转换为.py文件

    最近用wxpython写了一个脚本,其中要给窗体设置图标文件,需要单独的一个ico文件,这样就比较影响美观,另外打包的时候还要将图标文件一起打包很繁琐.这时候看到wxpython文件有一个工具img2 ...

  10. php如何将base64数据流文件转换为图片文件?

    2017-03-07 在开发中,自己遇到一个前端在上传图片的时候,使用的base64数据流文件显示的图片. 也就是说 <img src="data:image/jpg;base64,& ...

随机推荐

  1. Flex编程注意之直接获取某个组件的对象(this[]用法)通过id获取控件

    有这样一个需求:假如你new了一百次Button,同时这些button的id分别赋值如btn1.id = "button1"; btn2.id = "button2&qu ...

  2. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  3. Android ViewPager 应该及技巧

    1.   android 中的ViewPager 功能类似于iOS中的scrollView,实现最主要的页面的左右滑动功能.该类存在于Google的兼容包里面,所以在引用时记得在BuilldPath中 ...

  4. 安装linux系统并配置那点事

    安装完成后,将看到如下控制台: 输入以上安装信息中所填写的用户名(user),随后输入密码(user),即可登录 Ubuntu. 随时可使用 Ctrl + Alt 快捷键可离开虚拟机. 3 配置 Ub ...

  5. 用systemtap对sysbench IO测试结果的分析1

    http://www.actionsky.com/docs/archives/171  2016年5月6日  黄炎 近期在一些简单的sysbench IO测试中, 遇到了一些不合常识的测试结果. 从结 ...

  6. mysql常用命令大全 mysql常用命令总结

    原文地址:http://www.jbxue.com/db/12472.html 本文介绍下,mysql中常用的一些命令,包括创建与修改数据库.数据库中的表,mysql的权限管理命令grant.revo ...

  7. CentOS7 安装Docker报错

    安装报错: Transaction check error:  file /usr/lib/systemd/system/blk-availability.service from install o ...

  8. 代码片段------find批量处理

    应用案例: 当前目录下有若干目录,有多个目录下有一个名叫build.sh的脚本,但是没有可执行权限,现在要将所有的build.sh假如可执行权限. pengdl@debian:~/work/SDK_3 ...

  9. LeetCode9 Palindrome Number

    题意: Determine whether an integer is a palindrome. Do this without extra space.  (Easy) 分析: 自己考虑的方法是利 ...

  10. docker-hub 账户

    Docker Hub和docker及其组件一起工作.Docker Hub会帮助你和你的同事协作,并获取功能最全的docker.要做到这一点,它提供的服务有: Docker镜像主机 用户认证 自动镜像构 ...