当excel中的行或单元格没有被用到的时候,get到的会是null
可以封装一个util类,get不到的时候就create
public static XSSFCell getOrCreateCell(XSSFSheet sheet, int rowIndex, int colIndex) {
XSSFRow row = sheet.getRow(rowIndex);
if (row == null) {
row = sheet.createRow(rowIndex);
}
XSSFCell cell = row.getCell(colIndex);
if (cell == null) {
cell = row.createCell(colIndex);
}
return cell;
}