我在设值的时候 走到下面第2行代码 如果单元格未空,则报空指针异常,如果不为空则正常,怎么做呢?
public void setCellValue(int r, int c, String value) {
HSSFRow row = sheet.getRow(r);
HSSFCell cell = row.getCell((short)c);
HSSFRichTextString ts = new HSSFRichTextString(value);
cell.setCellValue(ts);
}
我在设值的时候 走到下面第2行代码 如果单元格未空color=darkblue[/color],则报空指针异常,如果不为空则正常,怎么做呢?
判断是否为空, 如是则使用 cell = row.createCell((short)c);
public void setCellValue(int r, int c, String value) {
HSSFRow row = sheet.getRow(r);
HSSFCell cell = row.getCell((short)c);
[color=darkblue]if(cell ==null ){
cell = row.createCell((short)c);
}[/color]
HSSFRichTextString ts = new HSSFRichTextString(value);
cell.setCellValue(ts);
}
你用try,catch包一下!