POI 操作EXCEL WORD完整例子示范(公司内部代码)

上传者: shonghuanc6 | 上传时间: 2019-12-21 21:05:06 | 文件大小: 9.22MB | 文件类型: rar
部分代码.................. . .. .. /** * 处理动态表格 * 默认取第二行第一列的标识 * @param table * @param ctRow * @param values 需要添加的数据 */ public static void processDynamicTable(XWPFTable table, CTRow ctRow, List values) { if(values==null || values.size()==0) return; for (Iterator iterator = values.iterator(); iterator.hasNext();) { String[] value = iterator.next(); XWPFTableRow newRow = new XWPFTableRow(ctRow,table); List cells = newRow.getTableCells(); if(cells==null || cells.size()==0) return; for (int j = 0; j < cells.size(); j++) { XWPFTableCell cell = cells.get(j); cell.removeParagraph(0); if(j<=value.length) cell.setText(value[j]); } table.addRow(newRow); } } /** * 处理表格 * @param doc * @param dataMap */ public static void processTable(XWPFDocument doc, Map dataMap) { Iterator iter = doc.getTablesIterator(); while(iter.hasNext()) { XWPFTable table = iter.next(); List rows = table.getRows(); if(rows==null || rows.size()==0) continue; CTRow ctRow = null; for (int i = 0; i < rows.size(); i++) { XWPFTableRow row = rows.get(i); ctRow = (CTRow)row.getCtRow().copy(); List cells = row.getTableCells(); if(cells==null || cells.size()==0) continue; //处理标致 boolean sign = false; for (int j = 0; j < cells.size(); j++) { XWPFTableCell cell = cells.get(j); if(cell.getText()==null) continue; if(i==1 && j==0) { //取第二行第一列的值,再添加table.关键字之后与dataMap匹配,有则当动态表格处理 String key = "table."+ cell.getText(); if(dataMap.containsKey(key)) { List values = (List)dataMap.get(key); table.removeRow(1); processDynamicTable(table, ctRow, values); //更新处理标致 sign = true; break; } } if(!cell.getText().startsWith("\\$") && cell.getText().endsWith("\\$")) continue; String key = cell.getText().replaceAll("\\$", ""); if(dataMap.containsKey(key)) {

文件下载

资源详情

[{"title":"( 47 个子文件 9.22MB ) POI 操作EXCEL WORD完整例子示范(公司内部代码)","children":[{"title":"POI","children":[{"title":"src","children":[{"title":"resource","children":[{"title":"wordtestaa.xml <span style='color:#111;'> 66.39KB </span>","children":null,"spread":false},{"title":"test_out.docx <span style='color:#111;'> 21.99KB </span>","children":null,"spread":false},{"title":"wordtest.xml <span style='color:#111;'> 152.61KB </span>","children":null,"spread":false},{"title":"wordtest.docx <span style='color:#111;'> 22.88KB </span>","children":null,"spread":false},{"title":"logo.gif <span style='color:#111;'> 3.42KB </span>","children":null,"spread":false}],"spread":true},{"title":"net","children":[{"title":"gbicc","children":[{"title":"word","children":[{"title":"PoiTest.java <span style='color:#111;'> 2.03KB </span>","children":null,"spread":false},{"title":"PoiUtil.java <span style='color:#111;'> 4.34KB </span>","children":null,"spread":false},{"title":"readWordByTable.java <span style='color:#111;'> 3.12KB </span>","children":null,"spread":false},{"title":"TRD.java <span style='color:#111;'> 3.96KB </span>","children":null,"spread":false},{"title":"CustomXWPFDocument.java <span style='color:#111;'> 3.06KB </span>","children":null,"spread":false}],"spread":true},{"title":"re","children":[{"title":"FixedAndTuple.java <span style='color:#111;'> 4.41KB </span>","children":null,"spread":false},{"title":"Header.java <span style='color:#111;'> 5.24KB </span>","children":null,"spread":false},{"title":"ZipUtil.java <span style='color:#111;'> 5.69KB </span>","children":null,"spread":false},{"title":"TableRC.java <span style='color:#111;'> 1.63KB </span>","children":null,"spread":false},{"title":"DelWordByTable.java <span style='color:#111;'> 6.23KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":"bin","children":[{"title":"resource","children":[{"title":"wordtestaa.xml <span style='color:#111;'> 66.39KB </span>","children":null,"spread":false},{"title":"test_out.docx <span style='color:#111;'> 21.99KB </span>","children":null,"spread":false},{"title":"wordtest.xml <span style='color:#111;'> 152.61KB </span>","children":null,"spread":false},{"title":"wordtest.docx <span style='color:#111;'> 22.88KB </span>","children":null,"spread":false},{"title":"logo.gif <span style='color:#111;'> 3.42KB </span>","children":null,"spread":false}],"spread":true},{"title":"net","children":[{"title":"gbicc","children":[{"title":"word","children":[{"title":"CustomXWPFDocument.class <span style='color:#111;'> 5.20KB </span>","children":null,"spread":false},{"title":"PoiTest.class <span style='color:#111;'> 3.40KB </span>","children":null,"spread":false},{"title":"PoiUtil.class <span style='color:#111;'> 5.62KB </span>","children":null,"spread":false},{"title":"TRD.class <span style='color:#111;'> 4.11KB </span>","children":null,"spread":false},{"title":"readWordByTable.class <span style='color:#111;'> 3.44KB </span>","children":null,"spread":false}],"spread":true},{"title":"re","children":[{"title":"ZipUtil.class <span style='color:#111;'> 5.30KB </span>","children":null,"spread":false},{"title":"Header.class <span style='color:#111;'> 4.87KB </span>","children":null,"spread":false},{"title":"DelWordByTable.class <span style='color:#111;'> 6.06KB </span>","children":null,"spread":false},{"title":"TableRC.class <span style='color:#111;'> 3.13KB </span>","children":null,"spread":false},{"title":"FixedAndTuple.class <span style='color:#111;'> 4.45KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":".classpath <span style='color:#111;'> 1.42KB </span>","children":null,"spread":false},{"title":"wordtest.docx.zip <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":".settings","children":[{"title":"org.eclipse.core.resources.prefs <span style='color:#111;'> 88B </span>","children":null,"spread":false},{"title":"org.eclipse.jdt.core.prefs <span style='color:#111;'> 629B </span>","children":null,"spread":false}],"spread":true},{"title":".project <span style='color:#111;'> 379B </span>","children":null,"spread":false},{"title":"lib","children":[{"title":"dom4j-1.6.1.jar <span style='color:#111;'> 306.54KB </span>","children":null,"spread":false},{"title":"junit-3.8.1.jar <span style='color:#111;'> 118.23KB </span>","children":null,"spread":false},{"title":"commons-logging-1.1.jar <span style='color:#111;'> 51.67KB </span>","children":null,"spread":false},{"title":"poi-3.7-20101029.jar <span style='color:#111;'> 1.60MB </span>","children":null,"spread":false},{"title":"dom4j-full.jar <span style='color:#111;'> 501.38KB </span>","children":null,"spread":false},{"title":"poi-ooxml-3.7-20101029.jar <span style='color:#111;'> 486.58KB </span>","children":null,"spread":false},{"title":"poi-scratchpad-3.7-20101029.jar <span style='color:#111;'> 820.53KB </span>","children":null,"spread":false},{"title":"log4j-1.2.13.jar <span style='color:#111;'> 349.79KB </span>","children":null,"spread":false},{"title":"xmlbeans-2.3.0.jar <span style='color:#111;'> 2.54MB </span>","children":null,"spread":false},{"title":"poi-examples-3.7-20101029.jar <span style='color:#111;'> 257.92KB </span>","children":null,"spread":false},{"title":"geronimo-stax-api_1.0_spec-1.0.jar <span style='color:#111;'> 27.92KB </span>","children":null,"spread":false},{"title":"poi-ooxml-schemas-3.7-20101029.jar <span style='color:#111;'> 3.78MB </span>","children":null,"spread":false}],"spread":false}],"spread":true}],"spread":true}]

评论信息

  • WARNING:: :
    非常好,已经用上了
    2018-03-05
  • cjzttt :
    是java 的 我还以为是 .net 的 不过谢谢分享
    2017-02-14
  • qilongpingchuan :
    首先,谢谢分享,生成文档代码可以运行,但是插入图片就报错了
    2016-09-18
  • yaozhuce999 :
    例子还可以,值得看看
    2015-06-05
  • jiangsw :
    不错,非常有帮助
    2015-03-13

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明