diff --git a/pom.xml b/pom.xml index 362ffca..638ccab 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,11 @@ poi 4.1.2 + + io.github.draco1023 + poi-tl-ext + 0.4.24 + org.apache.poi poi-ooxml @@ -92,7 +97,7 @@ com.alibaba fastjson - 1.2.47 + 1.2.83 org.jetbrains diff --git a/src/main/java/com/example/ts_obj/Util/XWPFHelperTable.java b/src/main/java/com/example/ts_obj/Util/XWPFHelperTable.java index b1b0381..1fca482 100644 --- a/src/main/java/com/example/ts_obj/Util/XWPFHelperTable.java +++ b/src/main/java/com/example/ts_obj/Util/XWPFHelperTable.java @@ -231,19 +231,19 @@ public class XWPFHelperTable { /** * @Description: 设置表格总宽度与水平对齐方式 */ - public void setTableWidthAndHAlign(XWPFTable table, String width, - STJc.Enum enumValue) { - CTTblPr tblPr = getTableCTTblPr(table); - // 表格宽度 - CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW(); - if (enumValue != null) { - CTJc cTJc = tblPr.addNewJc(); - cTJc.setVal(enumValue); - } - // 设置宽度 - tblWidth.setW(new BigInteger(width)); - tblWidth.setType(STTblWidth.DXA); - } +// public void setTableWidthAndHAlign(XWPFTable table, String width, +// STJc.Enum enumValue) { +// CTTblPr tblPr = getTableCTTblPr(table); +// // 表格宽度 +// CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW(); +// if (enumValue != null) { +// CTJc cTJc = tblPr.addNewJc(); +// cTJc.setVal(enumValue); +// } +// // 设置宽度 +// tblWidth.setW(new BigInteger(width)); +// tblWidth.setType(STTblWidth.DXA); +// } /** * @Description: 得到Table的CTTblPr,不存在则新建 diff --git a/src/main/java/com/example/ts_obj/controller/TypesetController.java b/src/main/java/com/example/ts_obj/controller/TypesetController.java index c9a396f..c1472a7 100644 --- a/src/main/java/com/example/ts_obj/controller/TypesetController.java +++ b/src/main/java/com/example/ts_obj/controller/TypesetController.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.poi.openxml4j.util.ZipSecureFile; import org.apache.poi.util.IOUtils; import org.apache.poi.xwpf.usermodel.*; +import org.ddr.poi.html.HtmlRenderPolicy; import org.freehep.graphicsio.emf.EMFHeader; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFRenderer; @@ -211,11 +212,13 @@ public class TypesetController { @ApiOperation(value = "读取文件") @PostMapping("readdoc") public ReturnValue myDocReader(String filename) { + System.out.println(filename); ArrayList al = new ArrayList(); try { File file = new File(this.BASE_DIR + filename); FileInputStream fis = new FileInputStream(file); XWPFDocument xdoc = new XWPFDocument(fis); + List list = xdoc.getParagraphs(); for (int i = 0; i < list.size(); i++) { String cache = ""; @@ -746,6 +749,7 @@ public class TypesetController { HashMap hashMap = new HashMap(); Style style = new Style(); style.setColor("0070C0"); + style.setVertAlign("superscript"); TextRenderData textRenderData = new TextRenderData(m.get("k"), style); hashMap.put("k",textRenderData); hashMap.put("c",m.get("content")); @@ -774,15 +778,24 @@ public class TypesetController { map.put("abbreviation", typesetInfo.getAbbreviation()); map.put("citation", (typesetInfo.getLittle_author() + ". " + typesetInfo.getInfo_title() + ". " + typesetInfo.getJabbr() + ". " + typesetInfo.getStage() + ". doi: 10.53388/" + typesetInfo.getDoi() + ".").replace("", "").replace("", "").replace("", "").replace("", "")); map.put("exeditor", typesetInfo.getUserAccount()); + if(typesetInfo.isHas_more()){ + MyParagraphRenderData hasmore_prd = crowStrNew("#These authors contributed equally to this work and are co-first authors for this paper.", tableDatas, imageDatas); + map.put("hasmore",hasmore_prd); + } map.put("received_date", typesetInfo.getReceived_date()); - map.put("accept_date", typesetInfo.getAccepted_date()); + ParagraphRenderData accept_p = new ParagraphRenderData(); + accept_p.addText(new TextRenderData("XXX",doi_s)); +// map.put("accept_date", typesetInfo.getAccepted_date()); + map.put("accept_date",accept_p); ParagraphRenderData od_p = new ParagraphRenderData(); od_p.addText(new TextRenderData("input online_date", doi_s)); map.put("online_date", od_p); map.put("ye", typesetInfo.getStage().substring(0, 4)); - ParagraphRenderData abstract_p = new ParagraphRenderData(); - abstract_p.addText(new TextRenderData(typesetInfo.getAbstractText())); +// ParagraphRenderData abstract_p = new ParagraphRenderData(); +// abstract_p.addText(new TextRenderData(typesetInfo.getAbstractText())); + MyParagraphRenderData abstract_p = crowStrNew(typesetInfo.getAbstractText(), tableDatas, imageDatas); map.put("abstract",abstract_p); +// map.put("abstract",typesetInfo.getAbstractText()); map.put("keywords", typesetInfo.getKeywords().replace("", "").replace("", "")); //主体部分 @@ -867,10 +880,22 @@ public class TypesetController { mainArr.add(hashMap1); otherNum++; }else{ + if(s.contains("")){ + HashMap hashMap = new HashMap(); + ParagraphRenderData paragraphRenderData = crowStrNew("",typesetInfo.getTables(),typesetInfo.getImages()); + hashMap.put("content",paragraphRenderData); + mainArr.add(hashMap); + } Map cache = new HashMap(); MyParagraphRenderData capd = crowStrNew(s,typesetInfo.getTables(),typesetInfo.getImages()); cache.put("content", capd); mainArr.add(cache); + if(s.contains("")){ + HashMap hashMap = new HashMap(); + ParagraphRenderData paragraphRenderData = crowStrNew("",typesetInfo.getTables(),typesetInfo.getImages()); + hashMap.put("content",paragraphRenderData); + mainArr.add(hashMap); + } } } map.put("main", mainArr); @@ -951,6 +976,7 @@ public class TypesetController { Configure config = Configure.builder().bind("content", new MyContentPolicy()).bind("data",new MyContentPolicy()) .bind("abstract", new ParagraphRenderPolicy()).bind("author", new ParagraphRenderPolicy()) .bind("doi", new ParagraphRenderPolicy()).bind("online_date", new ParagraphRenderPolicy()) + .bind("accept_date",new ParagraphRenderPolicy()).bind("hasmore",new ParagraphRenderPolicy()) .bind("peer", new ParagraphRenderPolicy()) .build(); XWPFTemplate template = XWPFTemplate.compile(this.BASE_DIR + myTemplate, config).render(map); @@ -1723,14 +1749,24 @@ public class TypesetController { if(s.isEmpty()){ p.addText(s); }else{ - textRenderCreate(s,p); - } - if(s.contains("")) { - ParagraphStyle paragraphStyle = new ParagraphStyle(); - paragraphStyle.setAlign(ParagraphAlignment.CENTER); - paragraphStyle.setBackgroundColor("DEEBF7"); - paragraphStyle.setSpacing(1.1); - p.setParagraphStyle(paragraphStyle); + if(s.contains("")){ + textRenderCreate(s,p); + ParagraphStyle paragraphStyle = new ParagraphStyle(); + paragraphStyle.setAlign(ParagraphAlignment.CENTER); + paragraphStyle.setBackgroundColor("DEEBF7"); + paragraphStyle.setSpacing(1.1); + p.setParagraphStyle(paragraphStyle); + }else{ + if(s.contains("")){ + s = s.replace("",""); + ParagraphStyle paragraphStyle = new ParagraphStyle(); + paragraphStyle.setIndentFirstLineChars(Double.valueOf("1")); + p.setParagraphStyle(paragraphStyle); + } + + + textRenderCreate(s,p); + } } return p; diff --git a/src/main/java/com/example/ts_obj/entity/TypesetInfo.java b/src/main/java/com/example/ts_obj/entity/TypesetInfo.java index b2b8bdf..89b509c 100644 --- a/src/main/java/com/example/ts_obj/entity/TypesetInfo.java +++ b/src/main/java/com/example/ts_obj/entity/TypesetInfo.java @@ -73,6 +73,9 @@ public class TypesetInfo implements Serializable { private String author_str; + //有多个第一作者 + private boolean has_more; + private List> authorAddressList; @@ -361,6 +364,18 @@ public class TypesetInfo implements Serializable { this.abbreviation = abbreviation; } + public boolean isHas_more() { + return has_more; + } + + public void setHas_more(boolean has_more) { + this.has_more = has_more; + } + + public void setTables(Map> tables) { + this.tables = tables; + } + @Override public String toString() { return "TypesetInfo{" + @@ -393,6 +408,8 @@ public class TypesetInfo implements Serializable { ", refers='" + refers + '\'' + ", info_state=" + info_state + ", userAccount='" + userAccount + '\'' + + ", author_str='" + author_str + '\'' + + ", has_more=" + has_more + ", authorAddressList=" + authorAddressList + ", images=" + images + ", tables=" + tables +