public static void CreateWord(string HtmlPath, string WordSavePath)
{
string inputName = HtmlPath;
//string ext = Path.GetExtension(inputName);
string outputName = WordSavePath;
if (File.Exists(inputName))
{
object oMissing = System.Reflection.Missing.Value;
object oTrue = true;
object oFalse = false;
Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word._Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
try
{ oWord.Visible = false;
// 这里是打开文件的扩展名
object openFormat = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatWebPages;
object openName = inputName; oWordDoc = oWord.Documents.Open(ref openName, ref oMissing, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref openFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object saveFileName = outputName;
oWord.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // 居中
oWord.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdWebView;//将web视图修改为默认视图,不然打开word的时候会以web视图去展示,而不是默认视图。(唯独这句代码是自己加的 = =|||)
//for (int i = 0; i < oWordDoc.Tables.Count; i++)
//{
// oWordDoc.Tables[i].PreferredWidth = 600;
//} // 这里是保存文件的扩展名
object saveFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault;
//去掉软回车
oWordDoc.Content.Find.Text = "^l";
object FindText, ReplaceWith, Replace;//
object MissingValue = Type.Missing;
FindText = "^l";//要查找的文本
ReplaceWith = "^p";//替换文本
Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
/**/
/*wdReplaceAll - 替换找到的所有项。
* wdReplaceNone - 不替换找到的任何项。
* wdReplaceOne - 替换找到的第一项。
* */
oWordDoc.Content.Find.ClearFormatting();
//移除Find的搜索文本和段落格式设置
if (oWordDoc.Content.Find.Execute(
ref FindText, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue, ref MissingValue,
ref ReplaceWith, ref Replace,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue))
{
} oWordDoc.SaveAs(ref saveFileName, ref saveFormat, ref oMissing, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
catch (Exception)
{
throw;
}
finally
{
oWordDoc.Close(ref oTrue, ref oMissing, ref oMissing);
oWord.Quit(ref oTrue, ref oMissing, ref oMissing);
} }
}

将PDF转化为wrod的更多相关文章

  1. .net core 2.2 使用imagemagick 将pdf转化为png

    工作需要将PDF文件每一页拆分为一个一个的png文件 测试环境:mac,visual studio for mac 2019 nuget:magick.net-Q16-AnyCPU 不能直接支持PDF ...

  2. 常用PDF文档开发库

    C++库: 1,PDF类库 PoDoFo   http://podofo.sourceforge.net/  PoDoFo 是一个用来操作 PDF 文件格式的 C++ 类库.它还包含一些小工具用来解析 ...

  3. 将word转化为swf 进行如同百度文库的般阅读

    实现如同百度文库那样类似功能需要进行一系列转化,一般流程想将word转化为pdf格式,再将pdf格式转化为swf格式.在网页上显示其实都是swf格式内容. 首先将word转化为swf,需要调用com组 ...

  4. pdf转html插件~~~pdf2htmlEX安装,配置及使用

    这是一个将pdf转化为html的服务,开源的. 此功能服务的代码在git上的地址为: https://github.com/coolwanglu/pdf2htmlEX/wiki 安装: 在ubuntu ...

  5. 在线预览文档(支持word、excel、ppt、pdf)+在线预览文档html版(转)

    1.首先上网搜索一下有什么解决方案 (1).将文档转换为html,只支持支持office文档 (2).将文档转换为flash,实现类似百度文库的效果,除支持office文档外还支持pdf (1) a. ...

  6. 不错的PDF开发库

    C++库: 1,PDF类库 PoDoFo   http://podofo.sourceforge.net/  PoDoFo 是一个用来操作 PDF 文件格式的 C++ 类库.它还包含一些小工具用来解析 ...

  7. itext5和itext7操作pdf平铺和图层叠加(tiling, and N-upping)

    区别 itext5 生成pdf版本:1.4(Acrobat5.x) itext7 生成pdf版本:1.7(Acrobat8.x) iText7生成的pdf文件大, itext7 Java库更加系统和完 ...

  8. css007 margin padding border

    css007 margin padding border 1.理解盒模型(盒模型:就是把一些东西,包括html各种标签都包含在一个 看不见的盒子里) 1/在web浏览器中任何标签都是一个盒子,内容的周 ...

  9. Ghostscript命令实践

    一. 将单张PDF文件igs.pdf转化为tiff文件. . gs -sDEVICE=tiffg4 -sOutputFile=igs.tiff -dMaxStripSize= igs.pdf -dAd ...

随机推荐

  1. jsp页面用DBHelper实现简单的登陆验证

    首先我们需要写一个简单的登陆页面login.jsp,然后用from表单提交给index.jsp页面.在index.jsp页面通过DBHelper连接数据库判断账号和密码,如果密码正确则显示登陆成功. ...

  2. 02-Python基础1

    本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 定义列表 ...

  3. Prometheus监控Docker Swarm集群(一)

    Prometheus监控Docker Swarm集群(一) cAdvisor简介 为了解决容器的监控问题,Google开发了一款容器监控工具cAdvisor(Container Advisor),它为 ...

  4. Sublime Text 3.1 注册码

    加入到hosts文件: 127.0.0.1 www.sublimetext.com 127.0.0.1 license.sublimehq.com hosts 文件的位置: Windows : c:/ ...

  5. 【loj - 3055】「HNOI2019」JOJO

    目录 description solution accepted code details description JOJO 的奇幻冒险是一部非常火的漫画.漫画中的男主角经常喜欢连续喊很多的「欧拉」或 ...

  6. (十二)maven-surefire-plugin,用于自动化测试和单元测试的

    原文链接:https://www.bbsmax.com/A/n2d9WPwJDv/ 1.简介 如果你执行过mvn test或者执行其他maven命令时跑了测试用例,你就已经用过maven-surefi ...

  7. 使用python解线性矩阵方程(numpy中的matrix类)

    这学期有一门运筹学,讲的两大块儿:线性优化和非线性优化问题.在非线性优化问题这里涉及到拉格朗日乘子法,经常要算一些非常变态的线性方程,于是我就想用python求解线性方程.查阅资料的过程中找到了一个极 ...

  8. 1、安装配置Git私有服务器

    安装并配置一个私有的Git服务器吧,这样自己的代码就可以进行版本控制了,当然版本控制的重要性嘛,Please Baidu. 系统环境:64位Win10 Version 1909 安装步骤: 1.下载j ...

  9. 商城05——首页轮播图显示实现&Redis环境搭建&Redis实现缓存

    1.   课程计划 1.首页轮播图的展示 2.首页大广告展示流程图 3.Redis的常用命令 4.Redis的服务器搭建 (集群的搭建) 5.向业务逻辑中添加缓存 6.Jedis的使用(redis的客 ...

  10. 07.DRF-序列化

    Serializer序列化器 序列化器的作用: 进行数据的校验 对数据对象进行转换 一.定义Serializer 1.1 定义方法 Django REST framework中的Serializer使 ...