Jul*_*ion 5 java apache apache-poi
我尝试使用Apache POI 4.0.0制作Word文档,但出现错误
线程“ AWT-EventQueue-0”中的异常java.lang.NoClassDefFoundError:org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:365)上的org / apache / commons / compress / archivers / zip / ZipFile在org.apache.poi.xwpf.usermodel.XWPFDocument。(XWPFDocument.java:149)的org.apache.poi.xwpf.usermodel.XWPFDocument.java:158处,在model.Model_dokumen.Cetak(Model_dokumen。 java:32)在view.Frame_surat.cetak_dan_simpanActionPerformed(Frame_surat.java:414)在view.Frame_surat.access $ 400(Frame_surat.java:23)在view.Frame_surat $ 5.actionPerformed(Frame_surat.java:211)在javax.swing。 javax.swing中的AbstractButton.fireActionPerformed(AbstractButton.java:2022)(javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2348))java.awt.Component处的javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)处的DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)java.awt.Component处的javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) javax.swing.JComponent.processMouseEvent(JComponent.java:3324)处的java.awt.Component.processEvent(Component.java:6298)处的java.awt.Container.processEvent(Container。的java.awt.Component.dispatchEventImpl(Component.java:4889)的java:2238)的java.awt.Component.dispatchEvent(Component.java:4711)的java.awt.Container.dispatchEventImpl(Container.java:2296)的Java java.awt.LightweightDispatcher上的java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4897)。java.awt.LightweightDispatcher.dispatchEvent(Container.java:4475)的java.awt.Container.dispatchEventImpl(Container.java:2282)的processMouseEvent(Container.java:4534)在java.awt.Window.dispatchEventImpl(Window.java) :2746)at java.awt.Component.dispatchEvent(Component.java:4711)at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)at java.awt.EventQueue.access $ 500(EventQueue.java:97)at java.awt.EventQueue $ 3.run(EventQueue.java:709)(位于java.awt.EventQueue $ 3.run(EventQueue.java:703)位于java.security.AccessController.doPrivileged(本机方法)位于java.security.ProtectionDomain $ JavaSecurity.ProtectionDomain中的JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)$ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)at java.awt.EventQueue $ 4.run(EventQueue.java:733)at java.awt.EventQueue $ 4.run(EventQueue.java:731)at java.security.AccessController.doPrivileged(Native Method)at java.security .ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)在java.awt.EventQueue.dispatchEvent(EventQueue.java:730)在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)在java.awt.EventDispatchThread。 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)处的pumpEventsForFilter(EventDispatchThread.java:116)在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.pumpEvents(EventDispatchThread.java:101)处的java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) :93),位于java.awt.EventDispatchThread。run(EventDispatchThread.java:82)原因:java.lang.ClassNotFoundException:java.net.URLClassLoader.findClass(URLClassLoader.java:381)上的org.apache.commons.compress.archivers.zip.ZipFile。在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:349)处的ClassLoader.loadClass(ClassLoader.java:424)在java.lang.ClassLoader.loadClass(ClassLoader.java:357)处...还有43个Blockquote另外43个Blockquote另外43个Blockquote
我遵循了该站点的教程:tutorials point,并且我尝试了博客,论坛等提供的任何解决方案,但对我来说没有用。这是我的代码:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import view.Frame_surat;
/**
*
* @author nasution
*/
public class Model_dokumen {
public void Cetak(Frame_surat fs) throws Exception {
try {
XWPFDocument document = new XWPFDocument();
// XWPFDocument document = new XWPFDocument();//blank document
//membuat paragraf
//membuat dokumen surat keluar
try (FileOutputStream outputStream = new FileOutputStream(new File("Surat_keluar.docx"))) {
//membuat paragraf
XWPFParagraph paragraf = document.createParagraph();
XWPFRun run = paragraf.createRun();
run.setText("ini adalah halaman dokumen yg baru saja dibuat menggunakan POI");
document.write(outputStream);
}
JOptionPane.showMessageDialog(null, "Surat keluar berhasil dibuat");
} catch (FileNotFoundException ex) {
Logger.getLogger(Model_dokumen.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Model_dokumen.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
对于 poi-4.1.0,我必须将这些添加到类路径中: dom4j-1.6.jar xmlbeans-3.1.0.jar commons-collections4-4.3.jar commons-compress-1.18.jar 然后才对 Excel.xlsx 起作用文件:
ExcelWBook = new XSSFWorkbook(ExcelFile);
Run Code Online (Sandbox Code Playgroud)
尝试搜索类名,然后下载 jar,您可能会找到指定的 jar 文件。“例如:XWPF jar 文件下载。” 并将XWPF的类下载为jar文件我之前遇到过这个问题,我像这样解决了它,但对我来说它是pdfBox。PS:尝试搜索“org.apache.poi.xwpf”的 jar 文件,你会得到更多结果。
归档时间: |
|
查看次数: |
25110 次 |
最近记录: |