I am trying to edit an excel file with apache poi in the following way:
public void generarOrdenDePago(Cliente cliente, Periodo periodo, OutputStream outputStream) {
try {
InputStream in = new FileInputStream("ordenPagoLimpia.xls");
try (Workbook wb = WorkbookFactory.create(in)) {
Sheet sheet = wb.getSheet("MySheet");
Row row = sheet.createRow(15); //El error sale aquí
Cell cell = row.createCell(2);
cell.setCellValue("nonononono");
wb.write(outputStream);
}
outputStream.flush();
outputStream.close();
} catch (IOException ex) {
System.out.println(ex);
} catch (EncryptedDocumentException | InvalidFormatException ex) {
Logger.getLogger(IGenerarOrdenPagoExcelFedex.class.getName()).log(Level.SEVERE, null, ex);
}
}
However, when executing the following line: Row row = sheet.createRow(15);
the system throws me a nullPointerException, but could not understand why.
This is the excel I'm trying to edit: