I have an Excel sheet with a table of 75 rows.
In the 76th row I have a Total function of each column =SUM(A1:A75)
and =SUM(B1:B75)
In the 77th to 92th rows I have an Excel chart which takes A1:A75 and B1:B75 for values
If I use Apache POI to populate all 75 rows, then everything looks great. (I am using XSSFWorkbook)
If I use Apache POI to populate just 30 rows, then I would like to delete rows 31 to 75. This is where I run into problems.
Were I to delete these Rows in Excel then the Total functions update, and the Excel chart updates to use A1:A30 and B1:B30, and the Excel chart moves up to row 31.
I would like to mirror this behaviour using Apache POI
This is what I have tried
xlsTable.shiftRows(75,91,-45)
(Rows 75 to 91 are the Apache Row equivalents of Excel Rows 76 to 92 and include the Total function and the chart)
I have also tried
for (int i = 75; i > 30; i--) {
Row r = CellUtil.getRow(i, xlsTable);
xlsTable.removeRow(r);
}
and
for (int i = 30; i < 75; i) {
Row r = CellUtil.getRow(i, xlsTable);
xlsTable.removeRow(r);
}
These just cause my sheet to become messy with #REF errors. I imagine that what I want may not be possible with POI, and that I would need to actually build my entire sheet for the requisite amount of rows, and then add the chart. However I thought I would ask!
HSSFRow rowToRemove = sheet.getRow(currentRowIndex); sheet.shiftRows(currentRowIndex+1, lastRowIndex, -1); sheet.removeRow(rowToRemove);
– Jimmy