diff --git a/pom.xml b/pom.xml index 9512755..38e801a 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 3.2.1 3.9.1 1.7 - 3.17 + 5.2.3 2.1.5 1.3.0 5.8.15 @@ -460,6 +460,27 @@ timi-inject 1.4.0 + + + org.apache.poi + poi-ooxml + ${poi.version} + + + + + xerces + xercesImpl + 2.12.2 + + + + + org.apache.logging.log4j + log4j-core + 2.21.0 + + diff --git a/src/main/java/com/zhangmeng/tools/controller/ExcelFileReadController.java b/src/main/java/com/zhangmeng/tools/controller/ExcelFileReadController.java new file mode 100644 index 0000000..338eaad --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/ExcelFileReadController.java @@ -0,0 +1,97 @@ +package com.zhangmeng.tools.controller; + + +import cn.hutool.core.lang.Console; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.sax.handler.RowHandler; +import com.zhangmeng.tools.utils.AlertUtils; +import com.zhangmeng.tools.utils.ImagePath; +import javafx.application.Platform; +import javafx.beans.property.SimpleObjectProperty; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.stage.FileChooser; +import javafx.stage.Stage; +import lombok.extern.slf4j.Slf4j; + +import java.io.File; +import java.util.List; +import java.util.Map; + +@Slf4j +public class ExcelFileReadController { + + @FXML + public Button file_choose; + + @FXML + public TableView result_view; + + @FXML + public TextField file_path; + + private final SimpleObjectProperty choose_file = new SimpleObjectProperty<>(null); + + @FXML + public Button open_excel; + + @FXML + public void initialize() { + + file_choose.setText(null); + ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE))); + iv.setPreserveRatio(true); + iv.setFitWidth(18); + file_choose.setGraphic(iv); + + //选择文件 + file_choose.setOnAction(event -> choose_file()); + + //打开文件 + open_excel.setOnAction(event -> { + + if (choose_file.getValue() == null) { + AlertUtils.alert_warning("请选择将要识别的pdf再试!"); + return; + } + + Stage alert = AlertUtils.alert_loading(file_choose.getScene().getWindow()); + new Thread(() -> { + + //打开文件 + readBySax(); + + Platform.runLater(() -> { + log.info("打开文件....."); + alert.close(); + }); + }).start(); + }); + } + + public void choose_file() { + Stage stage = new Stage(); + FileChooser dc = new FileChooser(); + dc.setTitle("文件选择"); + dc.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("类型", "*.xlsx")); + File file = dc.showOpenDialog(stage); + if (file != null) { + String path = file.getAbsolutePath(); + file_path.setText(path); + log.info("file_path:{}", path); + choose_file.set(file); + } + } + + public void readBySax(){ + ExcelReader reader = ExcelUtil.getReader(choose_file.getValue()); + List> readAll = reader.readAll(); + System.out.println(readAll); + + } +} diff --git a/src/main/java/com/zhangmeng/tools/controller/HomeController.java b/src/main/java/com/zhangmeng/tools/controller/HomeController.java index 0420897..cc0031b 100644 --- a/src/main/java/com/zhangmeng/tools/controller/HomeController.java +++ b/src/main/java/com/zhangmeng/tools/controller/HomeController.java @@ -681,4 +681,8 @@ public class HomeController implements Serializable { public void timeFx_fx_menu_item(ActionEvent actionEvent) { js_edit_list(3); } + + public void excel_read_menu_item(ActionEvent actionEvent) { + load_small_tools(21); + } } \ No newline at end of file diff --git a/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java b/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java index 45ca408..d23ff22 100644 --- a/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java +++ b/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java @@ -88,6 +88,7 @@ public class SmallToolsController { private AnchorPane log_console; private AnchorPane editPlusCode; private AnchorPane minioUpload; + private AnchorPane excel_read; @FXML private ListView listView; @@ -447,10 +448,33 @@ public class SmallToolsController { } minioUpload(flag); } + + if (newValue.getIndex() == 21){ + if (excel_read != null) { + flag = true; + } + excel_read(flag); + } } }); } + private void excel_read(boolean flag) { + //默认选择第一个 + listView.getSelectionModel().select(21); + if (!flag) { + try { + root = FXMLLoader.load(ResourcesUtils.getResource("excel-read")); + } catch (IOException e) { + e.printStackTrace(); + } + excel_read = root; + } else { + root = excel_read; + } + common_method(); + } + private void minioUpload(boolean flag) { //默认选择第一个 @@ -557,6 +581,7 @@ public class SmallToolsController { case LogConsole -> new Image("image/layui.png"); case EditPlusCode -> new Image("image/layui.png"); case MinioUpload -> new Image("image/layui.png"); + case ExcelRead -> new Image("image/layui.png"); }; } diff --git a/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java b/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java index e77a93c..e2747e3 100644 --- a/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java +++ b/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java @@ -55,7 +55,7 @@ public class AlertUtils { public static Stage alert_loading(Window window) { AnchorPane root = null; try { - root = FXMLLoader.load(ResourcesUtils.getResource("loading")); + root = FXMLLoader.load(ResourcesUtils.getResource("load-start")); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java index 44b47b6..8ada6ac 100644 --- a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java +++ b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java @@ -136,6 +136,7 @@ public class ResourcesUtils { LogConsole("日志输出", 18), EditPlusCode("edit-plus注册码", 19), MinioUpload("minio-upload文件上传", 20), + ExcelRead("excel-read(表格读取)", 21), ; SmallTools(String title, int index) { diff --git a/src/main/resources/fxml/excel-read.fxml b/src/main/resources/fxml/excel-read.fxml new file mode 100644 index 0000000..baba49c --- /dev/null +++ b/src/main/resources/fxml/excel-read.fxml @@ -0,0 +1,17 @@ + + + + + + + + + + +