当前位置: 首页 > news >正文

免费网站模板html网站跳转qq

免费网站模板html,网站跳转qq,网站建设都需要买什么东西,网站主机方式本文主要功能是解析word模板 这是一个word解析类#xff0c;因为我做的系统用到了而且没有可用的帮助类#xff0c;只能自己写。之前的实现方式是freemarker 模板解析。但是这次要求用poi不在使用freemarker。实现功能比较少#xff0c;主要是满足开发需求即可#xff0c;没…本文主要功能是解析word模板 这是一个word解析类因为我做的系统用到了而且没有可用的帮助类只能自己写。之前的实现方式是freemarker 模板解析。但是这次要求用poi不在使用freemarker。实现功能比较少主要是满足开发需求即可没有实现其它功能。实现功能如下 1、word内文本内容解析 2、word内表格内容解析 3、word内图片内容解析 4、word脚注内容解析 功能实现的比较匆忙没有好好设计如果可以将图标图片脚注等设置为实体类便于配置管理。 import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.util.Base64; import java.util.List; import java.util.Properties; import org.apache.poi.util.Units; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFFootnote; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFPicture; import org.apache.poi.xwpf.usermodel.XWPFRun; import org.apache.poi.xwpf.usermodel.XWPFTable; import org.apache.poi.xwpf.usermodel.XWPFTableCell; import org.apache.poi.xwpf.usermodel.XWPFTableRow; import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal; import org.springframework.util.PropertyPlaceholderHelper; import com.alibaba.cloud.commons.lang.StringUtils; /**  * 通过word模板生成新的word工具类  **  */ public class WordUtil {     public static final PropertyPlaceholderHelper helper new PropertyPlaceholderHelper(${, }); /**      * 根据模板生成新word文档 判断表格是需要替换还是需要插入判断逻辑有$为替换表格无$为插入      *       * param textMap 需要替换的信息集合      * return 成功返回true,失败返回false      */     public static void changWord(InputStream inputStream, Properties properties, int height, int width) { // InputStream in null;         try {             // 获取docx解析对象             XWPFDocument document new XWPFDocument(inputStream);             // 解析替换文本段落对象             WordUtil.changeText(document, properties);             // 解析替换表格对象             WordUtil.changeTable(document, properties);             // 替换文本中的图片             WordUtil.changePicture(document, properties, height, width);             // 脚注/尾注解析 footnote             WordUtil.changeFootNote(document, properties); File file new File(I://实体文件.docx);             FileOutputStream stream new FileOutputStream(file);             document.write(stream);             stream.close();             document.close(); } catch (Exception e) {             e.printStackTrace();         }     } /**      * 尾注解析      *       * param document      * param properties      */     public static void changeFootNote(XWPFDocument document, Properties properties) {         ListXWPFFootnote footNoteList document.getFootnotes();         for (XWPFFootnote footnote : footNoteList) {             ListXWPFParagraph paragraphs footnote.getParagraphs();             for (XWPFParagraph paragraph : paragraphs) {                 String text paragraph.getText();                 if (checkText(text)) {                     ListXWPFRun runs paragraph.getRuns();                     String key keyParam(runs);                     for (XWPFRun run : runs) {                         run.setText(, 0);                     }                     // 替换模板原来位置                     String value changeValue(key, properties);                     // 字符串中有可能是图片转换的字符串                     if (StringUtils.isNotEmpty(value)) {                         runs.get(0).setText(value, 0);                     } }             }         }     } /***      * 指定替换模板中的图片      *       * param document      * param filePath      * param height      * param width      */     public static void changePicture(XWPFDocument document, Properties properties, Integer height, Integer width) { // 获取段落集合         ListXWPFParagraph paragraphs document.getParagraphs();         for (XWPFParagraph paragraph : paragraphs) {             // 判断此段落时候需要进行替换             String text paragraph.getText();             if (checkText(text)) {                 ListXWPFRun runs paragraph.getRuns();                 String key keyParam(runs);                 for (XWPFRun run : runs) {                     // 字符串中有可能是图片转换的字符串                     String value changeValue(key, properties);                     if (value.startsWith(data:image)) {                         byte[] imageBytes Base64.getDecoder().decode(value.split(,)[1]); // 获取Base64编码后的图像数据部分 try(ByteArrayInputStream in new ByteArrayInputStream(imageBytes); ){// 创建ByteArrayInputStream对象                         // 添加图片                         XWPFPicture xwpfPicture run.addPicture(in, XWPFDocument.PICTURE_TYPE_JPEG, 图片1.jpg,                                 Units.toEMU(width), Units.toEMU(height));                         // 为图片添加边框                         xwpfPicture.getCTPicture().getSpPr().addNewLn().addNewSolidFill().addNewSchemeClr()                                 .setVal(STSchemeColorVal.Enum.forString(tx1));                         }catch(Exception e) {                             e.printStackTrace();                         }                     }                 }             }         }     } public static String keyParam(ListXWPFRun runs) {         if (runs.isEmpty()) {             return ;         }         StringBuffer st new StringBuffer();         // 转换为一个字符串 [${E_002, 1, }${E_002, 2, }${E_002, 3, }]         for (XWPFRun run : runs) {             st.append(run.text());         }         return st.toString().replace(,, );     } /**      * 替换段落文本      *       * param document docx解析对象      * param textMap  需要替换的信息集合      */     public static void changeText(XWPFDocument document, Properties properties) {         // 获取段落集合         ListXWPFParagraph paragraphs document.getParagraphs();         for (XWPFParagraph paragraph : paragraphs) {             // 判断此段落时候需要进行替换             String text paragraph.getText();             if (checkText(text)) {                 ListXWPFRun runs paragraph.getRuns();                 for (XWPFRun run : runs) {                     // 替换模板原来位置                     String value changeValue(run.toString(), properties);                     // 字符串中有可能是图片转换的字符串                     if (StringUtils.isNotEmpty(value) !value.startsWith(data:image)) {                         run.setText(value, 0);                     }                 }             }         } } /**      * 替换表格对象方法      *       * param document docx解析对象      * param textMap  需要替换的信息集合      */     public static void changeTable(XWPFDocument document, Properties properties) {         // 获取表格对象集合         ListXWPFTable tables document.getTables();         for (int i 0; i tables.size(); i) {             // 只处理行数大于等于2的表格且不循环表头             XWPFTable table tables.get(i);             if (table.getRows().size() 1) {                 // 判断表格是需要替换还是需要插入判断逻辑有$为替换表格无$为插入                 if (checkText(table.getText())) {                     ListXWPFTableRow rows table.getRows();                     // 遍历表格,并替换模板                     eachTable(rows, properties);                 }             }         }     } /**      * 遍历表格      *       * param rows    表格行对象      * param textMap 需要替换的信息集合      */     public static void eachTable(ListXWPFTableRow rows, Properties properties) {         for (XWPFTableRow row : rows) {             ListXWPFTableCell cells row.getTableCells();             for (XWPFTableCell cell : cells) {                 // 判断单元格是否需要替换                 if (checkText(cell.getText())) {                     // 基本一个单元格都是size1如果预防意外可以增加判断或者添加循环                     ListXWPFParagraph paragraphs cell.getParagraphs();                     // System.out.println(String.format(text:%s,paragraphs:%d,cell.getText(),                     // paragraphs.size()));                     // for (XWPFParagraph paragraph : paragraphs) {                     // ListXWPFRun runs paragraph.getRuns();                     // 替换模板原来位置                     XWPRunValue(paragraphs.get(0).getRuns(), properties);                     // }                 }             }         }     } /**      * 这个方法是一次处理一个单元格一个单元格内被解析成了 XWPFRun, 只给第一个 XWPFRun赋值即可其它都赋值      *       * param runs      * param textMap      */     public static void XWPRunValue(ListXWPFRun runs, Properties properties) {         if (runs.size() 1) {             runs.get(0).setText(changeValue(runs.get(0).toString(), properties), 0);             return;         }         StringBuffer st new StringBuffer();         // 转换为一个字符串 [${E_002, 1, }${E_002, 2, }${E_002, 3, }]         for (XWPFRun run : runs) {             //             st.append(run.text());             run.setText(, 0);         }         String value st.toString().replace(,, );         value changeValue(value, properties);         // 一次性替换全部的值         runs.get(0).setText(value, 0);     } /**      * 判断文本中时候包含$      *       * param text 文本      * return 包含返回true,不包含返回false      */     public static boolean checkText(String text) {         return (text.indexOf($) ! -1);     } /**      * 匹配传入信息集合与模板      *       * param value   模板需要替换的区域      * param textMap 传入信息集合      * return 模板需要替换区域信息集合对应值      */     public static String changeValue(String value, Properties properties) {         if (!checkText(value)) {             return value;         }         return helper.replacePlaceholders(value, properties);     } public static void main(String[] args) throws Exception {         // 从FTP读取文件模板         InputStream is new FileInputStream(new File(I://模板文件.docx)); // 填充文本和表格需要替换的数据         Properties properties new Properties();         properties.put(E_0001, 2000年01月01日);         properties.put(E_0002, 第一行);         properties.put(E_0003, 脚注解析异常);         // 图片字符串         properties.put(P01, data:image/jpg;base64,图片转换的字符串) ;         WordUtil.changWord(is, properties, 140, 400); } }
http://www.hkea.cn/news/14360666/

相关文章:

  • 无锡企业网站排名怎样才能建立自已的网站
  • 重庆网站推广系统重庆国外网站推广
  • 医院网站和微信公众号建设方案漫画网站建设教程视频
  • 淄博网站制作定制品牌网站建设的好处有什么用
  • 成都网页设计与网站建设云南建设厅官方网站
  • 高端网站建设谷美wordpress怎么注册用户名
  • 北京专业制作网站公司阿里云网站建设套餐
  • 北京性价比网站建设网店设计的意义
  • 单位门户网站建设工作建议wordpress国外主题破解
  • 网站主题及样式优化深圳 倡导居家办公
  • 企业网站的制作及维护wordpress 结构化数据
  • 惠州惠城网站建设东昌府区住房和城乡建设局网站
  • 济南网络推广新网站上线怎么做seo
  • 建个网站 网页空间多少网站开发都学什么
  • 网站域名怎样注销万能浏览器网页版
  • 设计网站案例网站义乌做网站多少钱
  • 太原谁想做网站wordpress接收邮件
  • 做网站编辑累吗网站搭建平台多少钱
  • 用云怎么做网站网页设计培训机构多少钱
  • it培训网站珍岛外贸网站建设
  • 深圳网站建设行吗wordpress主题 论坛
  • 百度搜索 相关网站佛山做礼物的网站
  • 企腾做的网站怎么样南山网站设计公司
  • 专业网站建设的意义广州seo排名
  • 湖南企业网站网站首页建设中页面
  • 公众号推广费用一般多少南宁seo多少钱报价
  • 网站底部浮动网站建设7个基本流程步骤有哪些
  • 优秀集团网站设计本地升级wordpress
  • 怎么做网站轮播图片河北 全部阳性了
  • 建设公司网站有什么好处dw做网站背景音乐