0

Excel ファイルの読み取りに問題があり、apache poi 3.9 で分析しています... 外部 JAR ファイルを追加しましたが、それでもエラーが発生します。ここに私のコード

import java.io.File;
import java.io.FileInputStream;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class loop {
     public static void main(String [] args) throws Exception
     {
         File excel= new File("C:\\Users\\songSent.xlsx");
         FileInputStream fis= new FileInputStream(excel);
         XSSFWorkbook wb= new XSSFWorkbook(fis);
         XSSFSheet ws= wb.getSheet("Input");

         int rowNum=ws.getLastRowNum() +1;
         int colNum=ws.getRow(0).getLastCellNum();
         String [][] data= new String[rowNum][colNum];

         for(int i=0; i<rowNum; i++)
         {
             XSSFRow row= ws.getRow(i);
             for(int j=0; j<colNum; j++)
             {
                XSSFCell cell=row.getCell(j);
                String value=cellToString(cell);

                data[i][j]=value;
                System.out.println("the value is " +value);
             }
         }
    }
    public static String cellToString(XSSFCell cell)
    {
        int type;
        Object result;
        type=cell.getCellType();

        switch (type){

        case 0:
          result=cell.getNumericCellValue();
          break;
        case 1:
          result=cell.getStringCellValue();
          break;
        default:
            throw new RuntimeException("There no support");

        }
        return result.toString();
     }
  }

これらは、プログラムを実行したときのエラーです

Exception in thread "main" java.lang.NoClassDefFoundError:org/apache/poi/hssf/usermodel/HSSFCell
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by:     java.lang.ClassNotFoundException:org.apache.poi.hssf.usermodel.HSSFCell
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 6 more
4

2 に答える 2

3

プログラムが"poi" jarを見つけられないことは、スタック トレースから明らかです。クラスパスが正しく設定されているかどうかを確認し、Eclipse (または他の IDE) から実行している場合は、ビルド パスに jar が追加されているかどうかを確認します。

于 2013-10-05T19:52:24.750 に答える