|
@@ -1,8 +1,5 @@
|
|
|
package org.springblade.manager.controller;
|
|
|
|
|
|
-import com.aspose.cells.LoadFormat;
|
|
|
-import com.aspose.cells.LoadOptions;
|
|
|
-import com.aspose.cells.SaveFormat;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.ss.util.RegionUtil;
|
|
@@ -10,16 +7,13 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
|
-import org.jsoup.nodes.Node;
|
|
|
-import org.jsoup.nodes.TextNode;
|
|
|
import org.jsoup.select.Elements;
|
|
|
-import org.jsoup.select.NodeTraversor;
|
|
|
-import org.jsoup.select.NodeVisitor;
|
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
|
import org.springblade.manager.utils.FileUtils;
|
|
|
|
|
|
-import java.io.*;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -27,17 +21,17 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
public class HtmlTableToExcelConverter {
|
|
|
|
|
|
- public static void main(String[] args) throws Exception {
|
|
|
- String html = "D:\\tools\\html\\1927983851351572480.html";
|
|
|
-
|
|
|
-
|
|
|
- InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(html);
|
|
|
- String htmlString = IoUtil.readToString(inputStreamByUrl);
|
|
|
-
|
|
|
- convertHtmlTableToExcel(htmlString);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
+// public static void main(String[] args) throws Exception {
|
|
|
+// String html = "D:\\tools\\html\\1927983851351572480.html";
|
|
|
+//
|
|
|
+//
|
|
|
+// InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(html);
|
|
|
+// String htmlString = IoUtil.readToString(inputStreamByUrl);
|
|
|
+//
|
|
|
+// convertHtmlTableToExcel(htmlString);
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
public static Workbook convertHtmlTableToExcel(String html) throws Exception {
|
|
|
Document doc = Jsoup.parse(html);
|
|
@@ -226,12 +220,12 @@ public class HtmlTableToExcelConverter {
|
|
|
adjustRowHeights(sheet);
|
|
|
|
|
|
// 写入文件
|
|
|
- try (FileOutputStream fos = new FileOutputStream("D:\\tools\\html\\234.xlsx")) {
|
|
|
- workbook.write(fos);
|
|
|
- }
|
|
|
- workbook.close();
|
|
|
+// try (FileOutputStream fos = new FileOutputStream("D:\\tools\\html\\234.xlsx")) {
|
|
|
+// workbook.write(fos);
|
|
|
+// }
|
|
|
+// workbook.close();
|
|
|
|
|
|
- return null;
|
|
|
+ return workbook;
|
|
|
}
|
|
|
|
|
|
// 修复合并单元格边框问题(使用指定样式)
|