diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/report/util/WordUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/report/util/WordUtil.java index d53f033a8..f5154f51d 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/report/util/WordUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/report/util/WordUtil.java @@ -31,6 +31,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageSz; @@ -749,33 +750,33 @@ public class WordUtil { ctTblWidth0.setW(BigInteger.valueOf(703)); //设置单元格边距 XWPFTableCell cell0 = table.getRow(i).getCell(0); - cellPadding(cell0); + cellPadding(cell0,String.valueOf(i)); CTTblWidth ctTblWidth1 = table.getRow(i).getCell(1).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth1.setType(STTblWidth.DXA); ctTblWidth1.setW(BigInteger.valueOf(1984)); //设置单元格边距 XWPFTableCell cell1 = table.getRow(i).getCell(1); - cellPadding(cell1); + cellPadding(cell1,planNumber); CTTblWidth ctTblWidth2 = table.getRow(i).getCell(2).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth2.setType(STTblWidth.DXA); ctTblWidth2.setW(BigInteger.valueOf(3543)); //设置单元格边距 XWPFTableCell cell2 = table.getRow(i).getCell(2); - cellPadding(cell2); + cellPadding(cell2,standardName); CTTblWidth ctTblWidth3 = table.getRow(i).getCell(3).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth3.setType(STTblWidth.DXA); ctTblWidth3.setW(BigInteger.valueOf(2081)); //设置单元格边距 XWPFTableCell cell3 = table.getRow(i).getCell(3); - cellPadding(cell3); + cellPadding(cell3,expirationDate); - table.getRow(i).getCell(0).setText(String.valueOf(i)); - table.getRow(i).getCell(1).setText(planNumber); - table.getRow(i).getCell(2).setText(standardName); - table.getRow(i).getCell(3).setText(expirationDate); +// table.getRow(i).getCell(0).setText(String.valueOf(i)); +// table.getRow(i).getCell(1).setText(planNumber); +// table.getRow(i).getCell(2).setText(standardName); +// table.getRow(i).getCell(3).setText(expirationDate); } private static void setCellIssue(XWPFTable table, int i, String planNumber, String standardName, String expirationDate,String implementTime) { //设置单元格高度 @@ -787,41 +788,41 @@ public class WordUtil { ctTblWidth0.setW(BigInteger.valueOf(708)); //设置单元格边距 XWPFTableCell cell0 = table.getRow(i).getCell(0); - cellPadding(cell0); + cellPadding(cell0,String.valueOf(i)); CTTblWidth ctTblWidth1 = table.getRow(i).getCell(1).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth1.setType(STTblWidth.DXA); ctTblWidth1.setW(BigInteger.valueOf(1990)); //设置单元格边距 XWPFTableCell cell1 = table.getRow(i).getCell(1); - cellPadding(cell1); + cellPadding(cell1,planNumber); CTTblWidth ctTblWidth2 = table.getRow(i).getCell(2).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth2.setType(STTblWidth.DXA); ctTblWidth2.setW(BigInteger.valueOf(3124)); //设置单元格边距 XWPFTableCell cell2 = table.getRow(i).getCell(2); - cellPadding(cell2); + cellPadding(cell2,standardName); CTTblWidth ctTblWidth3 = table.getRow(i).getCell(3).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth3.setType(STTblWidth.DXA); ctTblWidth3.setW(BigInteger.valueOf(1247)); //设置单元格边距 XWPFTableCell cell3 = table.getRow(i).getCell(3); - cellPadding(cell3); + cellPadding(cell3,expirationDate); CTTblWidth ctTblWidth4 = table.getRow(i).getCell(4).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth4.setType(STTblWidth.DXA); ctTblWidth4.setW(BigInteger.valueOf(1247)); //设置单元格边距 XWPFTableCell cell4 = table.getRow(i).getCell(4); - cellPadding(cell4); + cellPadding(cell4,implementTime); - table.getRow(i).getCell(0).setText(String.valueOf(i)); - table.getRow(i).getCell(1).setText(planNumber); - table.getRow(i).getCell(2).setText(standardName); - table.getRow(i).getCell(3).setText(expirationDate); - table.getRow(i).getCell(4).setText(implementTime); +// table.getRow(i).getCell(0).setText(String.valueOf(i)); +// table.getRow(i).getCell(1).setText(planNumber); +// table.getRow(i).getCell(2).setText(standardName); +// table.getRow(i).getCell(3).setText(expirationDate); +// table.getRow(i).getCell(4).setText(implementTime); } private static void setCellIssueOne(XWPFTable table, String number,String planNumber, String standardName, String expirationDate,String implementTime) { //设置单元格高度 @@ -833,41 +834,41 @@ public class WordUtil { ctTblWidth0.setW(BigInteger.valueOf(708)); //设置单元格边距 XWPFTableCell cell0 = table.getRow(0).getCell(0); - cellPadding(cell0); + cellPadding(cell0,number); CTTblWidth ctTblWidth1 = table.getRow(0).getCell(1).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth1.setType(STTblWidth.DXA); ctTblWidth1.setW(BigInteger.valueOf(1990)); //设置单元格边距 XWPFTableCell cell1 = table.getRow(0).getCell(1); - cellPadding(cell1); + cellPadding(cell1,planNumber); CTTblWidth ctTblWidth2 = table.getRow(0).getCell(2).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth2.setType(STTblWidth.DXA); ctTblWidth2.setW(BigInteger.valueOf(3124)); //设置单元格边距 XWPFTableCell cell2 = table.getRow(0).getCell(2); - cellPadding(cell2); + cellPadding(cell2,standardName); CTTblWidth ctTblWidth3 = table.getRow(0).getCell(3).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth3.setType(STTblWidth.DXA); ctTblWidth3.setW(BigInteger.valueOf(1247)); //设置单元格边距 XWPFTableCell cell3 = table.getRow(0).getCell(3); - cellPadding(cell3); + cellPadding(cell3,expirationDate); CTTblWidth ctTblWidth4 = table.getRow(0).getCell(4).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth4.setType(STTblWidth.DXA); ctTblWidth4.setW(BigInteger.valueOf(1247)); //设置单元格边距 XWPFTableCell cell4 = table.getRow(0).getCell(4); - cellPadding(cell4); + cellPadding(cell4,implementTime); - table.getRow(0).getCell(0).setText(number); - table.getRow(0).getCell(1).setText(planNumber); - table.getRow(0).getCell(2).setText(standardName); - table.getRow(0).getCell(3).setText(expirationDate); - table.getRow(0).getCell(4).setText(implementTime); +// table.getRow(0).getCell(0).setText(number); +// table.getRow(0).getCell(1).setText(planNumber); +// table.getRow(0).getCell(2).setText(standardName); +// table.getRow(0).getCell(3).setText(expirationDate); +// table.getRow(0).getCell(4).setText(implementTime); } private static void setCellAskOne(XWPFTable table, String number,String planNumber, String standardName, String expirationDate) { //设置单元格高度 @@ -879,33 +880,33 @@ public class WordUtil { ctTblWidth0.setW(BigInteger.valueOf(703)); //设置单元格边距 XWPFTableCell cell0 = table.getRow(0).getCell(0); - cellPadding(cell0); + cellPadding(cell0,number); CTTblWidth ctTblWidth1 = table.getRow(0).getCell(1).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth1.setType(STTblWidth.DXA); ctTblWidth1.setW(BigInteger.valueOf(1984)); //设置单元格边距 XWPFTableCell cell1 = table.getRow(0).getCell(1); - cellPadding(cell1); + cellPadding(cell1,planNumber); CTTblWidth ctTblWidth2 = table.getRow(0).getCell(2).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth2.setType(STTblWidth.DXA); ctTblWidth2.setW(BigInteger.valueOf(3543)); //设置单元格边距 XWPFTableCell cell2 = table.getRow(0).getCell(2); - cellPadding(cell2); + cellPadding(cell2,standardName); CTTblWidth ctTblWidth3 = table.getRow(0).getCell(3).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth3.setType(STTblWidth.DXA); ctTblWidth3.setW(BigInteger.valueOf(2081)); //设置单元格边距 XWPFTableCell cell3 = table.getRow(0).getCell(3); - cellPadding(cell3); + cellPadding(cell3,expirationDate); - table.getRow(0).getCell(0).setText(number); - table.getRow(0).getCell(1).setText(planNumber); - table.getRow(0).getCell(2).setText(standardName); - table.getRow(0).getCell(3).setText(expirationDate); +// table.getRow(0).getCell(0).setText(number); +// table.getRow(0).getCell(1).setText(planNumber); +// table.getRow(0).getCell(2).setText(standardName); +// table.getRow(0).getCell(3).setText(expirationDate); } @@ -941,20 +942,20 @@ public class WordUtil { ctTblWidth0.setW(BigInteger.valueOf(2296));//宽度通过计算得来-->列表实际宽度除以2.54再乘以1440 //设置单元格边距 XWPFTableCell cell0 = table.getRow(number).getCell(0); - cellPadding(cell0); + cellPadding(cell0,fieldName); CTTblWidth ctTblWidth1 = table.getRow(number).getCell(1).getCTTc().addNewTcPr().addNewTcW(); ctTblWidth1.setType(STTblWidth.DXA); ctTblWidth1.setW(BigInteger.valueOf(6015)); //设置单元格边距 XWPFTableCell cell1 = table.getRow(number).getCell(1); - cellPadding(cell1); + cellPadding(cell1,technologyTerritory); // XWPFParagraph para = table.getRow(number).getCell(1).getParagraphs().get(0); // XWPFRun run = para.createRun();//对某个段落设置格式 // run.addBreak();//换行 - - table.getRow(number).getCell(0).setText(fieldName); - table.getRow(number).getCell(1).setText(technologyTerritory); +// +// table.getRow(number).getCell(0).setText(fieldName); +// table.getRow(number).getCell(1).setText(technologyTerritory); } @@ -981,7 +982,7 @@ public class WordUtil { * 设置单元格边距 * @param cell */ - public static void cellPadding(XWPFTableCell cell){ + public static void cellPadding(XWPFTableCell cell,String text){ CTTc ctTc = cell.getCTTc(); CTTcPr cttcpr =ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr(); CTTcMar ctTcMar = cttcpr.isSetTcMar() ? cttcpr.getTcMar() : cttcpr.addNewTcMar(); @@ -990,6 +991,18 @@ public class WordUtil { // (ctTcMar.isSetRight() ? ctTcMar.getRight() : ctTcMar.addNewRight()).setW(BigInteger.valueOf(100)); // (ctTcMar.isSetBottom() ? ctTcMar.getBottom() : ctTcMar.addNewBottom()).setW(BigInteger.valueOf(100)); + //设置文本及文本的字体 + //获取 CTP + CTP ctP = (ctTc.sizeOfPArray() == 0) ? + ctTc.addNewP() : ctTc.getPArray(0); + //getParagraph(ctP) 获取 XWPFParagraph + XWPFParagraph par = cell.getParagraph(ctP); + //XWPFRun 设置格式 + XWPFRun run = par.createRun(); + run.setText(text); + run.setFontSize(10); + run.setFontFamily("Blue Sky Noto Regular"); + } }