本文介绍了如何解决java.lang.VerifyError:组织/阿帕奇/ POI / XSSF /的usermodel / XSSFWorkbook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取资产文件夹中的xlsx档案。我下面例外收到

before this exception, I received some warnings also like,

I have added poi 3.12 library on my application, libraries screenshot as below,

And I have checked poi-3.12 and poi-ooxml-3.12 jar files in Order and Export, screenshot as below,

I used below code,

        InputStream is = context.getAssets().open("sample.xlsx"));
        XSSFWorkbook workbook = new XSSFWorkbook(is);
        XSSFSheet sheet = workbook.getSheetAt(0);
        Cell cell = sheet.getRow(0).getCell(0);
        String value = cell.getStringCellValue() + "";

I want to read and write the .XLSX and .XLS files. How to resolve this issue?

Thanks in Advance.

解决方案

Firs you should connect to your project these jars.

Then use this code for reading

public static void readXLSXFile() throws IOException
    {
        InputStream ExcelFileToRead = new FileInputStream("C:/Test.xlsx");
        XSSFWorkbook  wb = new XSSFWorkbook(ExcelFileToRead);

        XSSFWorkbook test = new XSSFWorkbook();

        XSSFSheet sheet = wb.getSheetAt(0);
        XSSFRow row;
        XSSFCell cell;

        Iterator rows = sheet.rowIterator();

        while (rows.hasNext())
        {
            row=(XSSFRow) rows.next();
            Iterator cells = row.cellIterator();
            while (cells.hasNext())
            {
                cell=(XSSFCell) cells.next();

                if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING)
                {
                    System.out.print(cell.getStringCellValue()+" ");
                }
                else if(cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC)
                {
                    System.out.print(cell.getNumericCellValue()+" ");
                }
                else
                {
                    //U Can Handel Boolean, Formula, Errors
                }
            }
            System.out.println();
        }

    }

这篇关于如何解决java.lang.VerifyError:组织/阿帕奇/ POI / XSSF /的usermodel / XSSFWorkbook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:31