我嘗試讀取這個excel文件:Test.xlsx,要做到這一點,我用我在互聯網上發現了一個例子,但在Java讀取Excel中,變量是空
我用這個鏈接,因爲en例如: http://howtodoinjava.com/2013/06/19/readingwriting-excel-files-in-java-poi-tutorial/
它沒有工作。 我複製了該文件的網址,因此沒有錯誤。 每當我運行它,它只是顯示錯誤:[] 當我調試它時,它顯示我listize = 0
我應該改變什麼?
ArrayList<String> list = new ArrayList<String>();
@Override
public List<String> getExcel(){
try {
FileInputStream file = new FileInputStream(new File("C:\\Users\\user\\Documents\\Test.xlsx"));
//Create Workbook instance holding reference to .xlsx file
HSSFWorkbook workbook = new HSSFWorkbook(file);
//Get first/desired sheet from the workbook
HSSFSheet sheet = workbook.getSheet("Sheet1");
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
//For each row, iterate through all the columns
if (row.getRowNum() <= 7) {
continue;// skip to read the first 7 row of file
}
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
list.add(cell.getStringCellValue());
}
//System.out.println("");
}
file.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
這將有助於展示一些示例XML :) – tnw 2014-11-03 19:01:07
哪一個你需要?獲得了網絡和項目XML。 – 2014-11-03 19:04:29