2017-05-04 88 views
0

我想讀一個Excel表格 所以我想讀我的第一列數據和迭代所有行然後第二列 所以如何做到這一點。如何迭代第一列然後行讀取在Excel中的Excel表格

我已經使用行迭代先再依次coloumn

Iterator <Row> rowIterator = sheetName.iterator(); 

    while (rowIterator.hasNext()) { 
    Row row = rowIterator.next(); 
    Iterator <Cell> cellIterator = row.cellIterator(); 

    while (cellIterator.hasNext()) { 
    Cell cell = cellIterator.next(); 
    } 
    } 
+0

[這](http://stackoverflow.com/questions/1516144/how-to-read-and-write-excel-file-in-java)可能有助於 – andreim

+0

檢查[此](http://stackoverflow.com/questions/27499147/reading-specific-column-of-excel-into-java-program)和[this](http://stackoverflow.com/questions/5551815/read-a -single-column-of-excel-sheet-using-java) – Sajjad

回答

0

如果我理解你的問題正確,那麼你正在試圖首先遍歷列,然後行嘗試。這是你可能要做的。希望它能幫助:

Sheet sheet = workbook.getSheetAt(0); 
    for(int i=0; i<sheet.getRow(sheet.getTopRow()).getLastCellNum(); i++){ 
     Iterator<Row> rowIterator=sheet.rowIterator(); 
     while(rowIterator.hasNext()){ 
      System.out.println(rowIterator.next().getCell(i)); //do what you want 

     } 

    } 
+0

謝謝你的回答,我會試一試 –

+0

是的,它是先列行然後列。但是我無法跳過行並且無法獲取所需的行數據。 –

+0

你能解決這個問題嗎... –

相關問題