I am studying POI and I want to find a simple way to write in column B and in each row, certain values.
Right now I have the code below, which reads the spreadsheet, but does not write.
public static void main(String[] args) throws IOException, InvalidFormatException {
File CaminhoArquivo = new File("tools\\cnpj.xlsx");
XSSFWorkbook Planilha = new XSSFWorkbook(CaminhoArquivo);
XSSFSheet sheet = Planilha.getSheetAt(0);
int QuantidadeDeLinhas = sheet.getLastRowNum();
System.out.println("Quant. de LInhas: " + QuantidadeDeLinhas);
for (int i = 1; i <= QuantidadeDeLinhas; i++) {
Row coluna = sheet.getRow(i);
Cell resultado = coluna.getCell(1);
//Write Line
resultado.setCellValue("10");
}
Planilha.close();
FileOutputStream outFile = new FileOutputStream(new File("tools\\cnpj.xlsx"));
Planilha.write(outFile);
outFile.close();
System.out.println("Arquivo Excel editado com sucesso!");
}
ERROR
Exception in thread "main" java.lang.NullPointerException at lendoXlsx.xlsx.ReadExcel.main(ReadExcel.java:35)
//Write Line
resultado.setCellValue("10");
