我在读取 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