Explorar el Código

word导出相关修改

huZhiHao hace 5 años
padre
commit
1d96649465

+ 46 - 20
src/main/java/platform/common/util/word/ExportWord.java

@@ -4,9 +4,10 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
 import org.apache.poi.xwpf.usermodel.*;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
+import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -35,6 +36,16 @@ public class ExportWord {
         XWPFDocument doc = new XWPFDocument();
         createTitleParagraph(doc);
         createTableParagraph(doc, row, cols);
+//测试页眉设置
+//        CTP ctp = CTP.Factory.newInstance();
+//        XWPFParagraph paragraph = new XWPFParagraph(ctp, doc);//段落对象
+//        ctp.addNewR().addNewT().setStringValue("华丽的测试页眉2019051488888888");//设置页眉参数
+//        ctp.addNewR().addNewT().setSpace(SpaceAttribute.Space.PRESERVE);
+//        CTSectPr sectPr = doc.getDocument().getBody().isSetSectPr() ? doc.getDocument().getBody().getSectPr() : doc.getDocument().getBody().addNewSectPr();
+//        XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(doc, sectPr);
+//        XWPFHeader header = policy.createHeader(STHdrFtr.DEFAULT, new XWPFParagraph[] { paragraph });
+//        header.setXWPFDocument(doc);
+
         return doc;
     }
 
@@ -48,9 +59,9 @@ public class ExportWord {
         titleParagraph.setAlignment(ParagraphAlignment.CENTER);//样式居中
         XWPFRun titleFun = titleParagraph.createRun();    //创建文本对象
 //        titleFun.setText(titleName); //设置标题的名字
-//        titleFun.setBold(true); //加粗
+        titleFun.setBold(true); //加粗
 //        titleFun.setColor("000000");//设置颜色
-        titleFun.setFontSize(14);    //字体大小
+        titleFun.setFontSize(16);    //字体大小
         titleFun.setFontFamily("宋体");//设置字体
         //...
 //        titleFun.addBreak();    //换行
@@ -65,6 +76,8 @@ public class ExportWord {
 //        xwpfHelperTable.createTable(xdoc, rowSize, cellSize, isSetColWidth, colWidths)
         XWPFTable infoTable = document.createTable(rows, cols);
         xwpfHelperTable.setTableWidthAndHAlign(infoTable, "8500", STJc.CENTER);
+        int[] COLUMN_WIDTHS = new int[]{2500, 6000};
+        xwpfHelperTable.setTableWidth(infoTable, COLUMN_WIDTHS);
         //合并表格
 //        xwpfHelperTable.mergeCellsHorizontal(infoTable, 1, 1, 5);
 //        xwpfHelperTable.mergeCellsVertically(infoTable, 0, 4, 9);
@@ -75,17 +88,18 @@ public class ExportWord {
         List<XWPFTableRow> rowList = infoTable.getRows();
         for (int i = 0; i < rowList.size(); i++) {
             XWPFTableRow infoTableRow = rowList.get(i);
+            infoTableRow.setHeight(200);
             List<XWPFTableCell> cellList = infoTableRow.getTableCells();
             for (int j = 0; j < cellList.size(); j++) {
                 XWPFParagraph cellParagraph = cellList.get(j).getParagraphArray(0);
                 cellParagraph.setAlignment(ParagraphAlignment.LEFT);
                 cellParagraph.setIndentationLeft(50);
                 XWPFRun cellParagraphRun = cellParagraph.createRun();
-                cellParagraphRun.setFontSize(11);
+                cellParagraphRun.setFontSize(12);
                 cellParagraphRun.setFontFamily("宋体");
-//                if (i % 2 != 0) {
-//                    cellParagraphRun.setBold(true);
-//                }
+                if (j % 2 == 0) {
+                    cellParagraphRun.setBold(true);
+                }
             }
             //倒数第二格加五个回车
             if (i == rowList.size() - 2) {
@@ -94,7 +108,7 @@ public class ExportWord {
                     cellParagraph.setAlignment(ParagraphAlignment.LEFT);
                     cellParagraph.setIndentationLeft(50);
                     XWPFRun cellParagraphRun = cellParagraph.createRun();
-                    cellParagraphRun.setFontSize(11);
+                    cellParagraphRun.setFontSize(12);
                     cellParagraphRun.setFontFamily("宋体");
                     cellParagraphRun.addBreak();
                     cellParagraphRun.addBreak();
@@ -104,16 +118,16 @@ public class ExportWord {
                 }
             }
             //倒数第一格右对齐
-            if (i == rowList.size() - 1) {
-                for (int j = 0; j < cellList.size(); j++) {
-                    XWPFParagraph cellParagraph = cellList.get(j).getParagraphArray(0);
-                    cellParagraph.setAlignment(ParagraphAlignment.RIGHT);
-                    cellParagraph.setIndentationRight(100);
-                    XWPFRun cellParagraphRun = cellParagraph.createRun();
-                    cellParagraphRun.setFontSize(11);
-                    cellParagraphRun.setFontFamily("宋体");
-                }
-            }
+//            if (i == rowList.size() - 1) {
+////                for (int j = 0; j < cellList.size(); j++) {
+////                    XWPFParagraph cellParagraph = cellList.get(j).getParagraphArray(0);
+////                    cellParagraph.setAlignment(ParagraphAlignment.RIGHT);
+////                    cellParagraph.setIndentationRight(100);
+////                    XWPFRun cellParagraphRun = cellParagraph.createRun();
+////                    cellParagraphRun.setFontSize(12);
+////                    cellParagraphRun.setFontFamily("宋体");
+////                }
+////            }
         }
 //        xwpfHelperTable.mergeCellsBordersVertically(infoTable, 0, 4, 9);
         xwpfHelperTable.setTableHeight(infoTable, 560, STVerticalJc.CENTER);
@@ -147,6 +161,16 @@ public class ExportWord {
         List<List<Object>> tableData = (List<List<Object>>) dataList.get("TABLEDATA");
         XWPFTable table = document.getTableArray(0);
         fillTableData(table, tableData);
+        //测试页眉设置
+        CTP ctp = CTP.Factory.newInstance();
+        XWPFParagraph paragraph_ = new XWPFParagraph(ctp, document);//段落对象
+        ctp.addNewR().addNewT().setStringValue("华丽的测试页眉2019051488888888");//设置页眉参数
+        ctp.addNewR().addNewT().setSpace(SpaceAttribute.Space.PRESERVE);
+        CTSectPr sectPr = document.getDocument().getBody().isSetSectPr() ? document.getDocument().getBody().getSectPr() : document.getDocument().getBody().addNewSectPr();
+        XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
+        XWPFHeader header = policy.createHeader(STHdrFtr.DEFAULT, new XWPFParagraph[]{paragraph_});
+        header.setXWPFDocument(document);
+
         xwpfHelper.saveDocument(document, response);
     }
 
@@ -163,7 +187,9 @@ public class ExportWord {
             for (int j = 0; j < list.size(); j++) {
                 XWPFParagraph cellParagraph = cellList.get(j).getParagraphArray(0);
                 XWPFRun cellParagraphRun = cellParagraph.getRuns().get(0);
-                cellParagraphRun.setText(String.valueOf(list.get(j)));
+                String str = (String) list.get(j);
+                String newStr = str.replace("\n\n\n\t", "\r");
+                cellParagraphRun.setText(newStr);
             }
         }
     }

+ 31 - 0
src/main/java/platform/common/util/word/XWPFHelperTable.java

@@ -279,4 +279,35 @@ public class XWPFHelperTable {
             }
         }
     }
+
+    /**
+     * @Author: huZhiHao
+     * @Description: 设置列宽
+     * @Date: 2020/3/30
+     * @Params: [infoTable, colWidths]
+     * @Return: void
+     **/
+    public void setTableWidth(XWPFTable infoTable, int[] colWidths) {
+
+        List<XWPFTableRow> rows = infoTable.getRows();
+        for (XWPFTableRow row : rows) {
+            List<XWPFTableCell> cells = row.getTableCells();
+            for (int j = 0; j < cells.size(); j++) {
+                CTTcPr cttcpr = cells.get(j).getCTTc().addNewTcPr();
+                CTTblWidth cellw = cttcpr.addNewTcW();
+                cellw.setType(STTblWidth.DXA);
+                cellw.setW(BigInteger.valueOf(colWidths[j]));
+            }
+        }
+    }
+
+    public void setTableGridCol(XWPFTable table, int[] colWidths) {
+        CTTbl ttbl = table.getCTTbl();
+        CTTblGrid tblGrid = ttbl.getTblGrid() != null ? ttbl.getTblGrid()
+                : ttbl.addNewTblGrid();
+        for (int j = 0, len = colWidths.length; j < len; j++) {
+            CTTblGridCol gridCol = tblGrid.addNewGridCol();
+            gridCol.setW(new BigInteger(String.valueOf(colWidths[j])));
+        }
+    }
 }

+ 18 - 9
src/main/java/platform/modules/government/service/IndustrialLandSupplyDetailService.java

@@ -924,8 +924,10 @@ public class IndustrialLandSupplyDetailService extends BaseService<IndustrialLan
 //        params.put("apply_name", Constant.ProjectType.PROJECT_INTELLIGENT);
 //        String templateCode = Constant.SMS_TemplateCode.RPOJECT_APPROVAL_REMIND;
 
-        if (CommonUtils.isNull(approval) || Objects.equals(Constant.LandSupplyApproveStatus.COMMERCE_PENDING_SUBMIT, approval.getAfter_approvalstatus())) {
-            //待属地提交  或  商务局受理员待提交--》待商务局受理员审核 或 待咨询反馈
+        if (CommonUtils.isNull(approval)
+                || Objects.equals(Constant.LandSupplyApproveStatus.PLATE_WITHDRAW, approval.getAfter_approvalstatus())
+                || Objects.equals(Constant.LandSupplyApproveStatus.COMMERCE_PENDING_SUBMIT, approval.getAfter_approvalstatus())) {
+            //待属地提交 或  属地撤回  或  商务局受理员待提交--》待商务局受理员审核 或 待咨询反馈
 
             IndustrialLandSupplyConsultation industrialLandSupplyConsultation = new IndustrialLandSupplyConsultation();
             industrialLandSupplyConsultation.setIndustrial_land_supply_id(applyId + "");
@@ -2489,7 +2491,7 @@ public class IndustrialLandSupplyDetailService extends BaseService<IndustrialLan
         IndustrialLandSupplyDetail entity = this.findById(id);
 
         ExportWord ew = new ExportWord();
-        XWPFDocument document = ew.createXWPFDocument(6, 1);
+        XWPFDocument document = ew.createXWPFDocument(6, 2);
         List<List<Object>> list = new ArrayList<List<Object>>();
 
         String title = entity.getTitle();
@@ -2498,22 +2500,29 @@ public class IndustrialLandSupplyDetailService extends BaseService<IndustrialLan
         String consultationSummary = entity.getConsultation_summary_text();
 
         List<Object> tempList = new ArrayList<Object>();
-        tempList.add("项目标题:" + (title == null ? "" : title));
+        tempList.add("项目标题");
+        tempList.add(title == null ? "" : title);
         list.add(tempList);
         tempList = new ArrayList<Object>();
-        tempList.add("项目内容:" + (content == null ? "" : content));
+        tempList.add("项目内容");
+        tempList.add(content == null ? "" : content);
         list.add(tempList);
         tempList = new ArrayList<Object>();
-        tempList.add("用地信息:" + (location == null ? "" : location));
+        tempList.add("用地信息");
+        tempList.add(location == null ? "" : location);
         list.add(tempList);
         tempList = new ArrayList<Object>();
-        tempList.add("部门意见(商务汇总意见):" + (consultationSummary == null ? "" : consultationSummary));
+        tempList.add("部门意见\r" +
+                "(商务汇总意见)");
+        tempList.add(consultationSummary == null ? "" : consultationSummary);
         list.add(tempList);
         tempList = new ArrayList<Object>();
-        tempList.add("领导批示和会签意见:");
+        tempList.add("领导批示和会签意见");
+        tempList.add("");
         list.add(tempList);
         tempList = new ArrayList<Object>();
-        tempList.add("日期:" + DateUtil.getCurrentDateString("yyyy-MM-yy"));
+        tempList.add("日期");
+        tempList.add(DateUtil.getCurrentDateString("yyyy-MM-yy"));
         list.add(tempList);
 
         Map<String, Object> dataList = new HashMap<String, Object>();