思路是这样,先将word文件转换为HMTL文件通过Aspose.Words.dll 这个DLL

        /// <summary>/// word转成html/// </summary>/// <param name="wordFileName"></param>private string WordToHtml(string wordFileName, string folderName){string wordSaveFileName = wordFileName.ToString();string strSaveFileName = wordSaveFileName.Replace(wordSaveFileName.Substring(wordSaveFileName.LastIndexOf(".")), "") + @"\" + folderName + ".html";Aspose.Words.Document doc = new Aspose.Words.Document(wordFileName.ToString());doc.Save(strSaveFileName, Aspose.Words.SaveFormat.Html);return strSaveFileName;}

下面开始读取html 将html 文件转换为字符串,然后匹配富文本框,替换IMG路径

        /// <summary>/// 读取html文件,返回字符串/// </summary>/// <param name="strHtmlFileName"></param>/// <returns></returns>private string getHtml(string strHtmlFileName){System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("utf-8");StreamReader sr = new StreamReader(strHtmlFileName, encoding);string str = sr.ReadToEnd();sr.Close();return str;}/// <summary>/// 返回网页HMTL/// </summary>/// <param name="strHtml"></param>/// <returns></returns>private string findUsedFromHtml(string strHtml, string strFileName){string strStyle;string strBody;// stytle 部分int index = 0;int intStyleStart = 0;int intStyleEnd = 0;while (index < strHtml.Length){int intStyleStartTmp = strHtml.IndexOf("<style>", index);if (intStyleStartTmp == -1){break;}int intContentStart = strHtml.IndexOf("<!--", intStyleStartTmp);if (intContentStart - intStyleStartTmp == 9){intStyleStart = intStyleStartTmp;break;}else{index = intStyleStartTmp + 7;}}index = 0;while (index < strHtml.Length){int intContentEndTmp = strHtml.IndexOf("-->", index);if (intContentEndTmp == -1){break;}int intStyleEndTmp = strHtml.IndexOf("</style>", intContentEndTmp);if (intStyleEndTmp - intContentEndTmp == 5){intStyleEnd = intStyleEndTmp;break;}else{index = intContentEndTmp + 4;}}strStyle = strHtml.Substring(intStyleStart, intStyleEnd - intStyleStart + 8);// Body部分          int bodyStart = strHtml.IndexOf("<body");int bodyEnd = strHtml.IndexOf("</body>");strBody = strHtml.Substring(bodyStart, bodyEnd - bodyStart + 7);Regex reg = new Regex(@"(?is)(?<=>).*(?=</body>)", RegexOptions.IgnoreCase);//[^(<td>))] Match mc = reg.Match(strBody);strBody = mc.Value;//替换图片地址string fullName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1);string strOld = fullName.Replace("doc", "files").Replace(" ", "%20");string strNew = Request.ApplicationPath + "Upload/Product/PP_Doc/" + strOld;strBody = strBody.Replace(strOld, strNew);strBody = strBody.Replace("v:imagedata", "img");strBody = strBody.Replace("</v:imagedata>", "");strBody = strBody.Replace("<![endif]-->", "");strBody = strBody.Replace("<!--[endif]-->", "");strBody = strBody.Replace("<!--[if !supportLists]-->", "");strBody = strBody.Replace("<!--[if !vml]-->", "");strBody = strBody.Replace("<![if !vml]>", "");strBody = strBody.Replace("<![if !supportLists]>", "");strBody = strBody.Replace("<![endif]>", "");strBody = strBody.Replace("<!--[if gte vml 1]>", "");Regex RE = new Regex(@"<v:shape[\s\t\r\n\S]*?</v:shape>", RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);int cnt = RE.Matches(strBody).Count;strBody = RE.Replace(strBody, "");//strBody = strBody.Replace("<v:shape ", "<v:shape style='display:none;' ");//Sgxcn临时调试用-但不可去掉//string strInnerHtml = strEditorInnerHtml.Replace("EditorValue", Request.Form["content"].ToString() + strStyle + strBody);//this.DvEditor.InnerHtml = strInnerHtml;strBody.Replace("<body>", "");strBody.Replace("</body>", "");return strStyle + strBody;}/// <summary>/// 返回网页HTML/// </summary>/// <param name="strHtml"></param>/// <returns></returns>private string getUseHtml(string strHtml, string folderName){string strBody = strHtml;strBody = strBody.Replace("<body>", "");strBody = strBody.Replace("</body>", "");strBody = strBody.Replace("<html>", "");strBody = strBody.Replace("</html>", "");Regex RE = new Regex(@"<img[\s]+src[\s]*=[\s]*((['""](?<src>[^'""]*)[\'""])|(?<src>[^\s]*))", RegexOptions.Multiline);MatchCollection ms = RE.Matches(strBody);foreach (Match item in ms){strBody = strBody.Replace(item.Groups[3].Value, "/Upload/Product/PP_Doc/" + folderName.Replace(folderName.Substring(folderName.LastIndexOf(".")), "") + "/" + item.Groups[3].Value);}return strBody;}

前台的富文本 直接读取字符串就行了

转载于:https://www.cnblogs.com/Sprince/p/7404564.html

将word文件转换为富文本编辑支持图片相关推荐

  1. word 转 html cms,Java 将Word文件转换为HTML格式文件

    前言:在很多时候我们都需要到项目中导入word文档,但是后期再次在前段显示这个文档的时候前端往往需要的是html格式的,所以这个时候就会提出一个需求: 你们存文档的时候能不能存成html格式的?  于 ...

  2. 191210P4 Java富文本编辑之图片链接本地化

    Java富文本编辑之图片链接本地化 作者:邵发 官网:http://afanihao.cn/java 本文介绍在图文混编项目中(博客.新闻等),如何将富文本中的图片外链转为本地链接的问题.本文是Jav ...

  3. python批量pdf转word,python批量实现Word文件转换为PDF文件

    本文为大家分享了python批量转换Word文件为PDF文件的具体方法,供大家参考,具体内容如下 1.目的 通过万能的Python把一个目录下的所有Word文件转换为PDF文件. 2.遍历目录 作者总 ...

  4. 将PDF文件转换为高质量的图片:免费的在线PDF转换器

    在现代社会中,PDF文档是非常常见的一种文档格式.但是,在某些情况下,我们需要将PDF文件转换为高质量的图片,以方便分享和展示.本文将介绍几款免费的在线PDF转换器,帮助您将PDF文件快速.简单地转换 ...

  5. python批量操作word文档实战_python批量实现Word文件转换为PDF文件

    本文为大家分享了python批量转换Word文件为PDF文件的具体方法,供大家参考,具体内容如下 1.目的 通过万能的Python把一个目录下的所有Word文件转换为PDF文件. 2.遍历目录 作者总 ...

  6. LabWindows/CVI系列——CVI下Word文件转换为PDF文件

    CVI下Word文件转换为PDF文件 目录: 需求场景 环境说明 所需文件 步骤 需求场景: 在某型号机电集成测试系统中,需要将试验报表(Word格式)转换为PDF文档,以便不易修改和查看. 环境说明 ...

  7. 使用Jacob实现将Word文件转换为Pdf文件

    在某些业务场景下,可能需要将Word文件转换为Pdf文件的需求,Word文件编辑方便,而Pdf文件查看更方便,并且格式基本不会变化,同时可以避免被误编辑. 如果使用的是Java语言,那么可以借助于Ja ...

  8. 富文本编辑的图片在手机,移动端显示图片img太大,超出屏幕,出现滚动条,富文本中的图片如何修改样式

    富文本编辑的图片在手机,移动端显示图片太大,超出屏幕,出现滚动条,富文本中的图片如何修改样式 var html = res.data.details.replace(/<img([\s\w&qu ...

  9. vue项目引入富文本编辑,图片上传/视频上传

    1:下载富文本和更改图片大小 npm install quill-image-resize-module --save//更改img图片大小 npm install vue-quill-editor ...

最新文章

  1. jupyter添加标题、文字注释
  2. Spring rabbitmq消息机制--手动确认
  3. 重绘(repaint)与渲染(reflow)
  4. Tomcat高级部分-使用特定模块和软件反向代理请求到后端tomcat实现负载均衡和session保持...
  5. 【Android RTMP】音频数据采集编码 ( 音频数据采集编码 | AAC 高级音频编码 | FAAC 编码器 | Ubuntu 交叉编译 FAAC 编码器 )
  6. ORA-00600 [4400][48]错误一例
  7. 代码谱写传奇,深度揭秘中国开发者现状!
  8. 从外部CorDapp扩展和覆盖流
  9. ie 调用java的时候报错,调用javabean的非常郁闷的异常。
  10. 深入Atlas系列:综合示例(1) - 调用服务器端方法时直接获得客户端具体类型...
  11. xpath获取标签的属性值_论xpath与css定位方式
  12. mysql crud_如何使用Laravel和MySQL构建您的第一个CRUD应用
  13. aj6 stamps storm_曝光! “渣男”Travis Scott的AJ6下周发售,分手后货量大减...
  14. Mac教程——怎么升级系统版本
  15. 2021-07-28-飞桨课程笔记-关于数据获取途径与处理方面的技巧
  16. java判断访问设备类型
  17. 数字金额转化为汉字大写金额
  18. echarts 环状图中添加图片
  19. 大数据可视化的方法、挑战及进展
  20. Java菜鸟到大牛学习路线培训视频

热门文章

  1. IE11使用F12开发人员工具一片空白无法正常使用的解决方案
  2. Windows 10 更新到 Windows 11
  3. 排序算法——shell排序(希尔排序)
  4. 怎样在压力下开始工作?
  5. cmd解压zip文件
  6. 运维工作常见问题处理1-37(一)
  7. 线性代数(10): 正交与投影
  8. 施努卡:机器视觉系统的组成(视觉包括哪几部分)
  9. MySQL的学习入门五
  10. oracle中00942错误,ORA-00942错误分析