Ver código fonte

build 新版报告生成处理 超链接换行 合并单元格不分页

mamingxu 1 mês atrás
pai
commit
aebd5a4686

+ 52 - 0
easier-report-biz/src/main/java/com/yaoyicloud/tools/OfficeUtil1.java

@@ -122,6 +122,7 @@ public class OfficeUtil1 {
         return false;
     }
 
+    @SuppressWarnings("checkstyle:MethodLength")
     public static String formatHtml(String html) {
         Document doc = Jsoup.parse(html);
         Elements pTags = doc.select("p");
@@ -305,6 +306,16 @@ public class OfficeUtil1 {
         for (Element element : select5) {
             element.attr("style", element.attr("style") + "line-height: 1.5; margin-top: 5pt; margin-bottom: 5pt;");
         }
+        //超链接
+        Elements select9 = doc.select("p.X1.X9");
+        for (Element element : select9) {
+            element.attr("style", element.attr("style") + "word-break: break-all; overflow-wrap: anywhere; max-width: 100%;");
+        }
+        //1.3合并的单元格 不分页
+        Elements select11 = doc.select("td.X10.X11");
+        for (Element element : select11) {
+            element.attr("style", element.attr("style") + "page-break-inside: avoid;");
+        }
         addTableOfContents(doc);
 
         doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
@@ -314,6 +325,47 @@ public class OfficeUtil1 {
         return doc.html();
     }
 
+
+
+    /**
+     * 合并表格中相同内容的单元格
+     *
+     * @param doc HTML文档对象
+     */
+    public static void mergeSameContentCells(Document doc) {
+        Elements tables = doc.select("table");
+        for (Element table : tables) {
+            Elements rows = table.select("tr");
+            for (int colIndex = 0; colIndex < rows.first().select("td").size(); colIndex++) {
+                int rowspan = 1;
+                String currentCellText = "";
+                for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
+                    Element currentCell = rows.get(rowIndex).select("td").get(colIndex);
+                    String cellText = currentCell.text();
+                    if (rowIndex == 0) {
+                        currentCellText = cellText;
+                    } else {
+                        if (cellText.equals(currentCellText)) {
+                            rowspan++;
+                            currentCell.remove();
+                        } else {
+                            if (rowspan > 1) {
+                                Element prevCell = rows.get(rowIndex - rowspan).select("td").get(colIndex);
+                                prevCell.attr("rowspan", String.valueOf(rowspan));
+                            }
+                            rowspan = 1;
+                            currentCellText = cellText;
+                        }
+                    }
+                }
+                if (rowspan > 1) {
+                    Element lastCell = rows.get(rows.size() - rowspan).select("td").get(colIndex);
+                    lastCell.attr("rowspan", String.valueOf(rowspan));
+                }
+            }
+        }
+    }
+
     /**
      *     移除 white-space:pre-wrap 并替换为 normal
      */

+ 1 - 1
easier-report-biz/src/test/java/com/yaoyicloud/render/test/TestPdf.java

@@ -193,7 +193,7 @@ public class TestPdf {
 //        for (Element tr : trs) {
 //            String trStyle = tr.attr("style");
 //            trStyle = (trStyle == null) ? "" : trStyle;
-//            trStyle += " page-break-inside: avoid !important;"; // 强制不分页
+//            trStyle += " page-break-inside: avoid !important;"; // 强制不
 //            tr.attr("style", trStyle);
 //        }
 //