8

I'm trying to read the xlsx file from asset folder. I received below exception,

05-16 10:12:05.613: E/AndroidRuntime(2915): FATAL EXCEPTION: main 05-16 10:12:05.613: E/AndroidRuntime(2915): java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook

before this exception, I received some warnings also like,

  • Could not find method org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument$Factory.parse, referenced from method org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead

  • VFY: unable to resolve exception class 3612 (Lorg/apache/xmlbeans/XmlException;)

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

enter image description here

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

enter image description here

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.

8
  • do you have the option to check the deployable for the android? Just to check that the needed jars are there? Commented May 21, 2015 at 7:32
  • @OlimpiuPOP There is no separate jar files for Android development. Commented May 21, 2015 at 8:28
  • goto your bin file and delete the files there, re-add to the build path clean and rebuild. maybe it might help Commented May 21, 2015 at 19:07
  • where does the error occur? Phone or emulator? Or both? Commented May 22, 2015 at 6:32
  • @OlimpiuPOP Both emulator and Phone. Commented May 22, 2015 at 12:10

2 Answers 2

5

Firs you should connect to your project these jars.

jars you need

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();
        }

    }
Sign up to request clarification or add additional context in comments.

10 Comments

Already I have added those jar files in project build libraries.
Can you tell please your ide?
I'm using eclipse IDE.
So, try to remove all libraries and than connect again only these 4 jars. Maybe you have some duplication.
If it doesn't work, download these 2 jars, and try with them. github.com/andruhon/AndroidReadXLSX/tree/master/libs
|
0

Updated your code to able to read and write the .XLSX and .XLS files

InputStream is = context.getAssets().open("sample.xlsx"));
Workbook workbook = WorkbookFactory.create(is);
Sheet sheet = workbook.getSheetAt(0);
Cell cell = sheet.getRow(0).getCell(0);
String value = cell.getStringCellValue() + "";

For your libraries, please have a look here android getting java lang verify error when using external java lib

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.