Создание файла MS Word при нажатии на кнопку в графическом интерфейсе

125
11 августа 2019, 18:20

Пытаюсь получить строковую переменную из "TextField" и передать ее в создаваемый файл MS Word

 package sample.Controllers;
    import java.net.URL;
    import java.util.ResourceBundle;
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextField;
    import org.apache.poi.xwpf.usermodel.*;
    import java.io.*;

    public class Controller {

        public static String text;

        @FXML
        private ResourceBundle resources;
        @FXML
        private URL location;
        @FXML
        public Label result;
        @FXML
        private Button findButton;
        @FXML
        private TextField nameText;

        @FXML
        void initialize() {
            findButton.setOnAction((ActionEvent event) -> {
                text = nameText.getText();

                XWPFDocument document = new XWPFDocument();
                XWPFParagraph paragraph = document.createParagraph();
                XWPFRun run = paragraph.createRun();
                run.setText(String.valueOf(text));

                try {
                    FileOutputStream outputStream = new FileOutputStream("d://TEST//HELLO.docx");
                    document.write(outputStream);
                } catch (Exception e) {
                    System.out.println("WTF!");
                }
            });
        }
    }

После чего ловлю следующее:

"C:\Program Files\Java\jdk-10.0.1\bin\java.exe" "-javaagent:D:\IntelliJ IDEA Community Edition 2018.3.2\lib\idea_rt.jar=55531:D:\IntelliJ IDEA Community Edition 2018.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\oscar\IdeaProjects\JavaFxTest\out\production\JavaFxApplication;D:\poi-4.0.1\poi-4.0.1.jar;D:\poi-4.0.1\poi-ooxml-4.0.1.jar;D:\poi-4.0.1\poi-examples-4.0.1.jar;D:\poi-4.0.1\poi-excelant-4.0.1.jar;D:\poi-4.0.1\poi-scratchpad-4.0.1.jar;D:\poi-4.0.1\poi-ooxml-schemas-4.0.1.jar;D:\poi-4.0.1\ooxml-lib\curvesapi-1.05.jar;D:\poi-4.0.1\ooxml-lib\xmlbeans-3.0.2.jar sample.Main
Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile
    at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:366)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.newPackage(XWPFDocument.java:157)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:148)
    at sample.Controllers.Controller.lambda$initialize$0(Controller.java:44)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8865)
    at javafx.controls/javafx.scene.control.Button.fire(Button.java:200)
    at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
    at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3876)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1300(Scene.java:3604)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1874)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2613)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.archivers.zip.ZipFile
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    ... 50 more

Объясните, почему я неправ и в какую сторону гуглить?

READ ALSO
Не могу получить данные из базы данных

Не могу получить данные из базы данных

Пробую делать мини приложение, что-то типа доски объявленийНи как не получается у меня сделать поиск по фильтру

124
Как поместить объекты enum в коллекцию?

Как поместить объекты enum в коллекцию?

Есть объекты enum, надо их поместить в коллекциюКак это сделать?

127
List&lt;JPAEntity&gt; to DTO — как собрать статистику ПО ДНЯМ?

List<JPAEntity> to DTO — как собрать статистику ПО ДНЯМ?

Нужно сделать статистикуЕсть две даты

111
argmin() в Java

argmin() в Java

Существуют стандартные методы получения min(), max(), argmin() и argmax() почти в любом языкеЕсть ли такие в Java?

105