I have an existing xlsx file, on row 1 I have my headlines, what I need to is add new row at 2 and of course shift everything else down, and then add my data to this row. Can you please help me with this?
static void Append() throws EncryptedDocumentException, InvalidFormatException, IOException
{
InputStream inp = new FileInputStream("C:/workbook.xlsx");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.createRow((short) 2);
sheet.shiftRows(1, sheet.getLastRowNum()+1, 1, true,true);
row.createCell(0).setCellValue("A");
row.createCell(1).setCellValue("B");
row.createCell(2).setCellValue("This is a string");
row.createCell(3).setCellValue(true);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("C:/workbook.xlsx");
wb.write(fileOut);
fileOut.close();
}