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

挂甲寺网站建设如何营销推广

挂甲寺网站建设,如何营销推广,网页网站模板,吉林seo推广系统突然想起来有个小作业&#xff1a;需要根据提供的Word模板填充数据。这里使用POI写了一个小demo验证下。 测试用模板&#xff1a; 执行结果 1.引入依赖坐标 <dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId&…

突然想起来有个小作业:需要根据提供的Word模板填充数据。这里使用POI写了一个小demo验证下。

测试用模板:
在这里插入图片描述

执行结果
在这里插入图片描述

1.引入依赖坐标

        <dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency>

2.获取相关数据的方法

    private static Object getValueFromData(String key) {// 根据需要实现此方法以从数据源获取值// 例如,从数据库、配置文件或用户输入中获取值Map<String, Object> textMap = new HashMap<String, Object>();textMap.put("title","《模板》");textMap.put("myName","--尉某人--");textMap.put("today","2023-11-02");List<Map> tables = new ArrayList<Map>();Map<String, String> tableMap = new HashMap<String, String>();tableMap.put("name","尉某人");tableMap.put("age","26");tableMap.put("phone","189*******");tables.add(tableMap);tableMap = new HashMap<String, String>();tableMap.put("name","王某人");tableMap.put("age","28");tableMap.put("phone","186*******");tables.add(tableMap);tableMap = new HashMap<String, String>();tableMap.put("name","张某人");tableMap.put("age","24");tableMap.put("phone","130*******");tables.add(tableMap);textMap.put("tables",tables);return textMap.get(key);}

3.解析模板并填充数据

    public static void readTemplate() throws Exception {// 读取Word模板文件FileInputStream fis = new FileInputStream("C:\\Users\\Desktop\\template.docx");XWPFDocument document = new XWPFDocument(fis);// 获取所有段落List<XWPFParagraph> paragraphs = document.getParagraphs();for (XWPFParagraph paragraph : paragraphs) {List<XWPFRun> runs = paragraph.getRuns();for (XWPFRun run : runs) {String text = run.getText(0);if (text != null && text.startsWith("${")) {String key = text.substring(2, text.length() - 1);String value = getValueFromData(key).toString(); run.setText(value, 0);}}}// 获取表格List<XWPFTable> rowTables = document.getTables();for (XWPFTable table : rowTables) {// 遍历表格的每一行for (XWPFTableRow row : table.getRows()) {row.getCell(0).setText("尉某人");row.getCell(1).setText("26");row.getCell(2).setText("おひさしぶりだな");}}// 创建表格并填充数据List<Map> tables = (List<Map>) getValueFromData("tables");int size = tables.size();XWPFTable table = document.createTable(size+1, 3);table.getRow(0).getCell(0).setText("姓名");table.getRow(0).getCell(1).setText("年龄");table.getRow(0).getCell(2).setText("联系方式");for (int i = 0; i < tables.size(); i++) {Map<String,String> map = tables.get(i);XWPFTableRow row = table.getRow(i + 1);row.getCell(0).setText(map.get("name"));row.getCell(1).setText(map.get("age"));row.getCell(2).setText(map.get("phone"));}// 保存文件FileOutputStream fos = new FileOutputStream("C:\\Users\\Desktop\\output.docx");document.write(fos);fos.close();document.close();fis.close();}

4.测试结果

    public static void main(String[] args){try {readTemplate();System.out.println("执行成功!!!");} catch (Exception e) {e.printStackTrace();}}
http://www.shuangfujiaoyu.com/news/60079.html

相关文章:

  • 网站开发好公司seo网站推广免费
  • 运城网站建设价格商丘网站建设公司
  • 山东网站优化网络小说网站三巨头
  • 网络营销是什么的一项活动seo咨询服务
  • 海外做淘宝网站推广哪些app最挣钱
  • 做资源网站模板网站哪个好
  • 网站建设 软件开发的公司哪家好企业推广的渠道有哪些
  • 西安俄语网站建设免费b站推广网站链接
  • 网站制作方案怎么做吸引人的营销标题
  • asp.net 网站建设长沙企业seo优化
  • 免费咨询做网站百度搜索竞价推广
  • 展览公司网站建设方案6个好用的bt种子搜索引擎
  • 免费做网站广告沈阳企业网站seo公司
  • 网站开发赚钱方向全球网站流量排名查询
  • 网站开发 英语在线培训课程
  • wordpress最新主题下载地址独立站seo
  • 江苏网站开发建设百度指数的基本功能
  • 东营设计网站建设成都seo培训班
  • 网站建设公司的成本有哪些方面360收录
  • 常用网站开发技术热搜榜上2023年热门话题
  • 钟祥网站建设黑帽seo培训大神
  • 帝国手机网站怎么做可靠的网站优化
  • 手机上怎么做能打开的网站吗浙江seo技术培训
  • 网站模板带有sql后台下载竞价推广招聘
  • 郑州高新区做网站开发的公司百度搜索结果优化
  • angularjs 做团购网站桂林seo
  • 网站页面做多宽地方网站建设
  • 成都网站建设金网科技设计个人网站
  • 兴隆大院网站哪个公司做的百度网盘客户端下载
  • 网站开发与设计难嘛百度网页版浏览器入口