任何人都可以帮助的代码有什么问题?
二手图书馆
1. poi-3.10-final.jar
2.poi-ooxml-3.10.jar
3.xmlbeans-3.0.2.jar
4 .commons-collections4.4.2.jar
package xx;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
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 xx{
public static void main(String[] args) {
String file = "C:/Users/xxxx/Desktop/11-11-181111.xlsx";
try {
InputStream input = new BufferedInputStream(new FileInputStream(file));
// POIFSFileSystem fs = new POIFSFileSystem(input);
XSSFWorkbook wb = new XSSFWorkbook(input);
XSSFSheet sheet = wb.getSheetAt(0);
Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
XSSFRow row = (XSSFRow) rows.next();
System.out.println("\n");
Iterator cells = row.cellIterator();
while (cells.hasNext()) {
XSSFCell cell = (XSSFCell) cells.next();
if (XSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
System.out.print(cell.getNumericCellValue() + " ");
} else if (XSSFCell.CELL_TYPE_STRING == cell.getCellType()) {
System.out.print(cell.getStringCellValue() + " ");
} else if (XSSFCell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
System.out.print(cell.getBooleanCellValue() + " ");
} else if (XSSFCell.CELL_TYPE_BLANK == cell.getCellType()) {
System.out.print("BLANK");
} else {
System.out.print("Unknown cell type");
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
我,收到错误
run:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTSheet
at teamvision.Teamvision.main(Teamvision.java:33)
Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
C:\Users\xxxx\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
如果在读取xlsx文件时遇到错误,请告诉我,或者您知道其他轻松读取xlsx文件的方法,请建议我。预先感谢。