有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用ApachePOI的java读取excel

Here i am trying to read the excel file and want to edit it if required.

//code here
      try
       {
            FileInputStream file = new FileInputStream(new File("howtodoinjava_demo.xlsx"));

            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);  //ERROR HERE
            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);

            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()) 
                {
                 //code here
                }
            }
       }

Blockquote here i am getting error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap at com.Edetails.Dao.ReadExcel.main(ReadExcel.java:27) Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more


共 (1) 个答案

  1. # 1 楼答案

    我用的是不同版本的POI jar。而且我忘了包括dom4j。jar与该项目有关

    加上那个罐子后,它就可以正常工作了。请参考此link获取最新的poi jar