我實際上試圖用Apache POI讀取XLS文件,但我的代碼無法正常工作。 IntelliJ告訴我,在第28行中,創建XSSFWorkbook會造成麻煩。如果你在這裏,你會有一個簡短的看法,也許會回答嗎?Java中的Apache POI導致麻煩(XSSFWorkbook)
package Parse;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
public class poi {
public static void main(String[] args) {
try {
FileInputStream file = new FileInputStream(new File("C:\\Users\\jd\\Desktop\\test\\VW_XML\\in_xls.xlsx"));
//Create workbook instance
XSSFWorkbook workbook = new XSSFWorkbook(file);
//read sheet
XSSFSheet sheet = workbook.getSheetAt(0);
//iterate rows
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
// for each row all columns
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
//check cell type
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "t");
break;
}
}
System.out.println("");
}
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
異常stacktrace? – Naren
IntelliJ如何向您顯示問題在哪裏?或者它實際上是你讀的堆棧跟蹤?如果是積極的,也許你可以與我們分享。 –
引起︰java.lang.ClassNotFoundException︰org.apache.xmlbeans.XmlException – Paulquappe