|
@@ -31,7 +31,7 @@ public class WordPoiExporter {
|
|
|
FileOutputStream out = new FileOutputStream(path);
|
|
|
|
|
|
doc.write(out);
|
|
|
- //saveAsPdf(doc, pdfFilePath);
|
|
|
+ saveAsPdf(doc, pdfFilePath);
|
|
|
out.close();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -55,6 +55,9 @@ public class WordPoiExporter {
|
|
|
if (runText == null) continue;
|
|
|
if (runText.indexOf("${")>-1 && runText.indexOf("${image")==-1){
|
|
|
System.out.println(runText);
|
|
|
+ if(runText.indexOf("}")==-1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
//获取变量属性值
|
|
|
String key=runText.substring(runText.indexOf("${")+2,runText.indexOf("}"));
|
|
|
String[] keys=key.split(":");
|
|
@@ -103,17 +106,19 @@ public class WordPoiExporter {
|
|
|
for (XWPFParagraph p : cell.getParagraphs()) {
|
|
|
String text = p.getText();
|
|
|
if (text.contains("${tableRow:")) {
|
|
|
+ tbl.removeRow(tbl.getRows().indexOf(row));
|
|
|
String key=text.substring(text.indexOf("${")+2,text.indexOf("}"));
|
|
|
String[] keys=key.split(":");
|
|
|
// 找到表格占位行
|
|
|
// 获取原行(这里选择第一行作为示例)
|
|
|
JSONObject obj = jsonObject.getJSONObject(keys[1]);
|
|
|
System.out.println(JSONObject.toJSONString(keys));
|
|
|
+ if(obj==null)continue;
|
|
|
JSONArray tableData = obj.getJSONArray(keys[2]);
|
|
|
if (tableData != null && tableData.size() > 0) {
|
|
|
addTableRows(tbl, tableData, row);
|
|
|
}
|
|
|
- tbl.removeRow(tbl.getRows().indexOf(row));
|
|
|
+
|
|
|
} else {
|
|
|
replaceTextWithFormat(p, jsonObject);
|
|
|
}
|