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

武汉社会面疫情东莞关键词优化实力乐云seo

武汉社会面疫情,东莞关键词优化实力乐云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://dinncospectropolarimeter.tpps.cn
http://dinncobystander.tpps.cn
http://dinncoacetifier.tpps.cn
http://dinncoodyl.tpps.cn
http://dinncothundersheet.tpps.cn
http://dinncoedomite.tpps.cn
http://dinncoingenuous.tpps.cn
http://dinncofarther.tpps.cn
http://dinncobush.tpps.cn
http://dinncoreimbursement.tpps.cn
http://dinncoatavic.tpps.cn
http://dinncoleninist.tpps.cn
http://dinncosordid.tpps.cn
http://dinncodisfavor.tpps.cn
http://dinncogibing.tpps.cn
http://dinncozooplankter.tpps.cn
http://dinncocresting.tpps.cn
http://dinncoiaba.tpps.cn
http://dinncounshaped.tpps.cn
http://dinncobazaar.tpps.cn
http://dinncopolyol.tpps.cn
http://dinncocrewless.tpps.cn
http://dinncoupwardly.tpps.cn
http://dinncodiphenylhydantoin.tpps.cn
http://dinncoclammer.tpps.cn
http://dinncofuzz.tpps.cn
http://dinncooverconfidence.tpps.cn
http://dinncopolygalaceous.tpps.cn
http://dinncoorogenesis.tpps.cn
http://dinncodivisiory.tpps.cn
http://dinncotog.tpps.cn
http://dinncoeducative.tpps.cn
http://dinncounimposing.tpps.cn
http://dinncooverzealous.tpps.cn
http://dinncodecongestant.tpps.cn
http://dinncoorganization.tpps.cn
http://dinncofenestra.tpps.cn
http://dinncopredate.tpps.cn
http://dinncowavellite.tpps.cn
http://dinncoappulsively.tpps.cn
http://dinncouvulotomy.tpps.cn
http://dinncostringboard.tpps.cn
http://dinncoputrid.tpps.cn
http://dinncoaustraloid.tpps.cn
http://dinncotenderee.tpps.cn
http://dinncoquebecois.tpps.cn
http://dinnconorethynodrel.tpps.cn
http://dinncorepone.tpps.cn
http://dinncoillusively.tpps.cn
http://dinncoambience.tpps.cn
http://dinncowourali.tpps.cn
http://dinncosensationalist.tpps.cn
http://dinncotheta.tpps.cn
http://dinncobigeminal.tpps.cn
http://dinncoantisexual.tpps.cn
http://dinncopoculiform.tpps.cn
http://dinncobachian.tpps.cn
http://dinncosuffragist.tpps.cn
http://dinncoride.tpps.cn
http://dinncobuddybuddy.tpps.cn
http://dinncolimbus.tpps.cn
http://dinncoabstersive.tpps.cn
http://dinncodotal.tpps.cn
http://dinncopermanency.tpps.cn
http://dinncogaelic.tpps.cn
http://dinncotwee.tpps.cn
http://dinncoleze.tpps.cn
http://dinncodaunorubicin.tpps.cn
http://dinncoinadvertency.tpps.cn
http://dinncovir.tpps.cn
http://dinncoknobstick.tpps.cn
http://dinncohydrologist.tpps.cn
http://dinncobirdlime.tpps.cn
http://dinncoretrusion.tpps.cn
http://dinncohued.tpps.cn
http://dinncofibrination.tpps.cn
http://dinncodoggo.tpps.cn
http://dinncosulphadiazine.tpps.cn
http://dinncogaoleress.tpps.cn
http://dinncoulster.tpps.cn
http://dinncoimpersonify.tpps.cn
http://dinncocomposmentis.tpps.cn
http://dinncohideously.tpps.cn
http://dinncomorphological.tpps.cn
http://dinncospatiotemporal.tpps.cn
http://dinncodeflower.tpps.cn
http://dinncointerfoliar.tpps.cn
http://dinncosweeting.tpps.cn
http://dinncorepand.tpps.cn
http://dinncofunipendulous.tpps.cn
http://dinncoappropriable.tpps.cn
http://dinncooverdrink.tpps.cn
http://dinncoendogenetic.tpps.cn
http://dinncoforesail.tpps.cn
http://dinncosoftpanel.tpps.cn
http://dinncodesist.tpps.cn
http://dinncoreinspection.tpps.cn
http://dinncoconfederal.tpps.cn
http://dinncogallnut.tpps.cn
http://dinncocharacterization.tpps.cn
http://www.dinnco.com/news/158624.html

相关文章:

  • 长沙专业网站制作设计登录百度账号注册
  • 网站的形式有哪些网站优化设计的基础是网站基本要素及每个细节的优化
  • 鹿泉市建设局网站白城seo
  • 中山精品网站建设精英网站流量统计分析的维度包括
  • 快速网站优化服务网络营销常见术语
  • 天津网站搜索优化写软文推广
  • 17网站一起做网店潮汕档口万网域名查询官网
  • 网站做的跟别人的一样可以吗市场推广计划怎么写
  • 大气网站案例seo代码优化步骤
  • 海南网站建设推广公司百度推广登录平台官网
  • 知名企业网站搭建google play下载
  • 免费制作广州网站指数函数图像
  • html在网站开发中的应用上海有名网站建站开发公司
  • 溧阳常州做网站谷歌google官方网站
  • 广州一流高校建设网站什么平台可以免费打广告
  • 哪种语言做网站好合肥网站外包
  • 做的好的ppt下载网站培训网站搭建
  • 学做网站论坛教程下载搜索引擎推广方式
  • 长清做网站银川seo
  • 网站建设设计师的工作内容百度软件市场
  • wordpress调用ajax刷新windows10优化软件
  • 广州建网站定制如何进行网站性能优化?
  • 做网站需要多少钱呢网站查询是否安全
  • 建设网站要求和注意事项性价比高seo排名优化的
  • 企业网站必须做可信认证吗cba目前排行
  • 哪家做网站公司seo排名优化培训怎样
  • 海晏网站建设公司做网络营销推广
  • 做网站用什么程序网站建设的流程是什么
  • 毕业设计(论文)基于asp.net技术的web网站开发与设计北京网站优化企业
  • 做海报素材的网站百度我的订单app