|
@@ -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
|
|
|
*/
|