Tag: nullpointerexception hssf

Java – 无法在Excel单元格中写入

FileInputStream file = new FileInputStream(new File("//Users//"+ usr +"//Desktop//TNA//output//output.xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheet("Sheet1"); Cell name_c = null; Cell department_c = null; Cell prev_depart_c = null; HSSFRow row = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); department_c = sheet.getRow(2).getCell(1); // throws exception here department_c.setCellValue(department); prev_depart_c = sheet.getRow(3).getCell(1); prev_depart_c.setCellValue(prev_depart); emp_no_c = sheet.getRow(4).getCell(1); […]