使用java从Excel中打印10和11列的值

我有代码打印excel单元格的所有值,但它忽略了空白单元格。 有没有办法打印空白单元格的值(null)呢?

还有可能打印特定的2列(如空白单元格)像第10和第11列?

以下是我的代码。 请build议我可以在下面的代码中更改什么?

package excel; import java.io.File; import java.io.FileInputStream; import java.util.Iterator; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class Excel { public static void main(String[] args) { try { FileInputStream file = new FileInputStream(new File("C:\\Users\\gur29175\\Desktop\\1.xlsx")); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = new XSSFWorkbook(file); XSSFSheet sheet = workbook.getSheetAt(0); //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 Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); //Check the cell type and format accordingly System.out.print(cell.getStringCellValue() + "\t"); } System.out.println(""); } file.close(); } catch (Exception e) { e.printStackTrace(); } } } 

 Row row = rowIterator.next(); for(int i = 0; i < row.getLastCellNum(); i++) { Cell cell = row.getCell(i); if(cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { // handle not null values }else{ // handle null values } }