使用apache poi库无法从excel中读取

时间:2017-04-17 10:37:14

标签: java excel apache apache-poi

代码:

private void readExcelFile() {

        try{


            String inFileName = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/"+"Book1.xlsx";

            File file = new File(inFileName);
            Workbook workBook = WorkbookFactory.create(file);
            Sheet sheet  = workBook.getSheetAt(0);


            Iterator<Row> rowIter = sheet.rowIterator();

            while(rowIter.hasNext()){


                Row myRow =rowIter.next();
                Iterator<Cell> cellIter = myRow.cellIterator();


                while(cellIter.hasNext()){
                    Cell myCell = cellIter.next();



                    Log.w("FileUtils", "Cell Value: " +  myCell.toString());
                    Toast.makeText(getApplicationContext(), "cell Value: " + myCell.toString(), Toast.LENGTH_SHORT).show();
                }
            }
        }catch (Exception e){e.printStackTrace(); }

        return;
    }

错误:

org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found    
  at org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
  at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
  at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
  at org.apache.poi.javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
  at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
  at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
  at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
  at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:130)
  at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:295)
  at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:264)
  at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:226)
  at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory

0 个答案:

没有答案