|
|
|
@@ -105,40 +105,44 @@ public class WordUtil { |
|
|
|
if(rows.size()<2){ |
|
|
|
throw new Exception("tableIndex对应表格应该为2行"); |
|
|
|
} |
|
|
|
//模板的那一行 |
|
|
|
XWPFTableRow tmpRow = rows.get(2); |
|
|
|
List<XWPFTableCell> tmpCells = null; |
|
|
|
List<XWPFTableCell> cells = null; |
|
|
|
XWPFTableCell tmpCell = null; |
|
|
|
tmpCells = tmpRow.getTableCells(); |
|
|
|
|
|
|
|
String cellText = null; |
|
|
|
String cellTextKey = null; |
|
|
|
Map<String,Object> totalMap = null; |
|
|
|
for (int i = 0, len = params.size(); i < len; i++) { |
|
|
|
Map<String,String> map = params.get(i); |
|
|
|
// 创建新的一行 |
|
|
|
XWPFTableRow row = table.createRow(); |
|
|
|
// 获取模板的行高 设置为新一行的行高 |
|
|
|
row.setHeight(tmpRow.getHeight()); |
|
|
|
cells = row.getTableCells(); |
|
|
|
for (int k = 0, klen = cells.size(); k < klen; k++) { |
|
|
|
tmpCell = tmpCells.get(k); |
|
|
|
XWPFTableCell cell = cells.get(k); |
|
|
|
cellText = tmpCell.getText(); |
|
|
|
if (StringUtils.isNotBlank(cellText)) { |
|
|
|
//转换为mapkey对应的字段 |
|
|
|
cellTextKey = cellText.replace("$", "").replace("{", "").replace("}", ""); |
|
|
|
if (map.containsKey(cellTextKey)) { |
|
|
|
// 填充内容 并且复制模板行的属性 |
|
|
|
setCellText(tmpCell,cell,map.get(cellTextKey)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// 删除模版行 |
|
|
|
table.removeRow(1); |
|
|
|
table.addRow(rows.get(2),2); |
|
|
|
|
|
|
|
// //模板的那一行 |
|
|
|
// XWPFTableRow tmpRow = rows.get(2); |
|
|
|
// List<XWPFTableCell> tmpCells = null; |
|
|
|
// List<XWPFTableCell> cells2 = null; |
|
|
|
// XWPFTableCell tmpCell = null; |
|
|
|
// tmpCells = tmpRow.getTableCells(); |
|
|
|
// |
|
|
|
// String cellText = null; |
|
|
|
// String cellTextKey = null; |
|
|
|
// Map<String,Object> totalMap = null; |
|
|
|
// for (int i = 0, len = params.size(); i < len; i++) { |
|
|
|
// Map<String,String> map = params.get(i); |
|
|
|
// // 创建新的一行 |
|
|
|
// XWPFTableRow row = table.createRow(); |
|
|
|
// // 获取模板的行高 设置为新一行的行高 |
|
|
|
// row.setHeight(tmpRow.getHeight()); |
|
|
|
// cells = row.a(); |
|
|
|
// for (int k = 0, klen = tmpCells.size(); k < klen; k++) { |
|
|
|
// tmpCell = tmpCells.get(k); |
|
|
|
// XWPFTableCell cell = cells.get(k); |
|
|
|
// cellText = tmpCell.getText(); |
|
|
|
// if (StringUtils.isNotBlank(cellText)) { |
|
|
|
// //转换为mapkey对应的字段 |
|
|
|
// cellTextKey = cellText.replace("$", "").replace("{", "").replace("}", ""); |
|
|
|
// if (map.containsKey(cellTextKey)) { |
|
|
|
// // 填充内容 并且复制模板行的属性 |
|
|
|
// setCellText(tmpCell,cell,map.get(cellTextKey)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// } |
|
|
|
// // 删除模版行 |
|
|
|
// table.removeRow(2); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|