Browse Source

[合同][修改][开发结算单]

release_toaliyun_real
luozukai 6 years ago
parent
commit
5c7de5f6dc
3 changed files with 49 additions and 47 deletions
  1. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java
  2. +48
    -46
      mallinkService/src/main/java/com/iformall/utils/WordUtil.java
  3. BIN
      mallinkService/src/main/resources/contract-word-template/settle.docx

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java View File

@@ -844,7 +844,7 @@ public class WxBillAllServiceImpl implements WxBillAllService {
}
wordDocTableVo.setParams(rowsParams);
wordDocTableVo.setTableIndex(0);
wordDocTableVo.setRowIndex(1);
wordDocTableVo.setRowIndex(2);

String templatePath = "contract-word-template/settle.docx";
String filepath = fmUploadDir;


+ 48
- 46
mallinkService/src/main/java/com/iformall/utils/WordUtil.java View File

@@ -99,59 +99,61 @@ public class WordUtil {
public static void insertValueToTable(XWPFDocument xwpfDocument, WordDocTableVo wordDocTableVo) throws Exception {
List<XWPFTable> tableList = xwpfDocument.getTables();
XWPFTable table = tableList.get(wordDocTableVo.getTableIndex());
List<XWPFTableRow> rows = table.getRows();

int rowIndex = wordDocTableVo.getRowIndex();
XWPFTableRow tmpRow = rows.get(rowIndex);
addOrRemoveRow(table,wordDocTableVo.getParams().size(),wordDocTableVo.getRowIndex());

int row = wordDocTableVo.getRowIndex();
for (List<String> stringList : wordDocTableVo.getParams()) {
table.addRow(tmpRow,rowIndex);
rowIndex++;
//替换新行内容
XWPFTableRow tableRow = rows.get(rowIndex);
row++;
for (int i = 0; i < stringList.size(); i++) {
tableRow.getTableCells().get(i).setText(stringList.get(i));
table.getRow(row).getCell(i).setText(stringList.get(i));
}
}
tmpRow.getTableCells().get(0).setText("aaaa");

// //模板的那一行
// 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);
table.removeRow(wordDocTableVo.getRowIndex());
}

/*
* @param table 对应表格
* @param add 增加或删除行数 if add>0 增加行 add<0 删除行
* @param fromRow 添加开始行位置(fromRow-1是模版行)
*/
public static void addOrRemoveRow(XWPFTable table, int add,int fromRow) {
XWPFTableRow row = table.getRow(fromRow-1);
if(add>0)
{
while(add>0)
{
copyPro(row,table.insertNewTableRow(fromRow));
add--;
}
}
else
{
while(add<0)
{
table.removeRow(fromRow-1);
add++;
}
}
}



public static void copyPro(XWPFTableRow sourceRow,XWPFTableRow targetRow) {
//复制行属性
targetRow.getCtRow().setTrPr(sourceRow.getCtRow().getTrPr());
List<XWPFTableCell> cellList = sourceRow.getTableCells();
if(null==cellList)
{
return ;
}
//添加列、复制列以及列中段落属性
XWPFTableCell targetCell = null;
for(XWPFTableCell sourceCell:cellList)
{
targetCell = targetRow.addNewTableCell();
//列属性
targetCell.getCTTc().setTcPr(sourceCell.getCTTc().getTcPr());
//段落属性
targetCell.getParagraphs().get(0).getCTP().setPPr(sourceCell.getParagraphs().get(0).getCTP().getPPr());
}
}
}

BIN
mallinkService/src/main/resources/contract-word-template/settle.docx View File


Loading…
Cancel
Save