XSSFWorkbook错误

时间:2015-09-04 00:41:00

标签: java eclipse apache-poi import-from-excel

我是POI的新手。我试图在Eclipse中使用下面的代码读取xlsx文件。 我没有使用Maven,据我所知,我已经导入了所有相关的包(dom4.jar,poi.jar,poi-ooxml.jar,poi-ooxml-schemas.jar,xmlbeans.jar)。 示例代码是

...

    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            try {
                readFromExcel();
            } catch (IOException e1) {
                e1.printStackTrace();
            }


        }
    });

...

    public static void readFromExcel() throws IOException{

        System.out.println("Inside readFromExcel ");


        try
        {
            FileInputStream file = new FileInputStream(new File("C:\\Users\\TestBed.xlsx"));

            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);

            //Iterate through each rows one by one
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext())
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();

                while (cellIterator.hasNext())
                {
                    Cell cell = cellIterator.next();
                    //Check the cell type and format accordingly
                    switch (cell.getCellType())
                    {
                        case Cell.CELL_TYPE_NUMERIC:
                            System.out.print(cell.getNumericCellValue() + "t");
                            break;
                        case Cell.CELL_TYPE_STRING:
                            System.out.print(cell.getStringCellValue() + "t");
                            break;
                    }
                }
                System.out.println("");
            }
            file.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }       

    }

Eclipse报告的一些警告

&#34;从未使用过导入org.apache.poi.xssf.usermodel.XSSFCell&#34;

&#34;从未使用过导入org.apache.poi.xssf.usermodel.XSSFRow&#34;

Eclipse报告的错误是

线程中的异常&#34; AWT-EventQueue-0&#34; java.lang.VerifyError :(类:org / apache / poi / xssf / usermodel / XSSFWorkbook,方法:removeSheetAt签名:(I)V)函数的不兼容参数     在MainPage.readFromExcel(MainPage.java:263)     在MainPage $ 2.actionPerformed(MainPage.java:223)     在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)     在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2341)     在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)     在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)     在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)     at java.awt.Component.processMouseEvent(Component.java:6516)     在javax.swing.JComponent.processMouseEvent(JComponent.java:3321)     在java.awt.Component.processEvent(Component.java:6281)     at java.awt.Container.processEvent(Container.java:2229)     at java.awt.Component.dispatchEventImpl(Component.java:4872)     at java.awt.Container.dispatchEventImpl(Container.java:2287)     at java.awt.Component.dispatchEvent(Component.java:4698)     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)     at java.awt.Container.dispatchEventImpl(Container.java:2273)     at java.awt.Window.dispatchEventImpl(Window.java:2719)     at java.awt.Component.dispatchEvent(Component.java:4698)     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:740)     at java.awt.EventQueue.access $ 300(EventQueue.java:103)     at java.awt.EventQueue $ 3.run(EventQueue.java:699)     at java.awt.EventQueue $ 3.run(EventQueue.java:697)     at java.security.AccessController.doPrivileged(Native Method)     at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)     at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:87)     at java.awt.EventQueue $ 4.run(EventQueue.java:713)     at java.awt.EventQueue $ 4.run(EventQueue.java:711)     at java.security.AccessController.doPrivileged(Native Method)     at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)     at java.awt.EventQueue.dispatchEvent(EventQueue.java:710)     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)     at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

非常感谢您的帮助。

感谢。

0 个答案:

没有答案