Why does Apache POI read the row which has been manually erased? - java

I am trying to figure out why the row on excel gets uploaded which is manually erased(NOT Row delete from right click). Here is the scenario:
PS- I have a logic to trace the empty rows. If no of blank == myColumnCount, I skip the row. Somehow the blank count goes at least greater than 0. Hence gets uploaded
I enter the first row data
I enter the second row
I erase the cells manually of the second row
The data remains only on the first row
I save the file and upload it, POI reads the second row as empty row.
I understand the concept of Physical number of rows but confused as to why this scenario returns the row which has no data ?

Related

Group excel cells in POI and having the first row as "main"

I use POI to generate an excel sheet. When grouping rows using
curSheet.groupRow(firstRow, lastRow)
I noticed that the main Row that stays before collapsing is the last row of the grouping (the row with number lastRow).
How can I change it to first row?
Figured it out.
curSheet.setRowSumsBelow(false)

Using XSSF POI removeRow(row) API, does not clear cell comments, if present

I am using Apache POI XSSF APIs to remove one or more rows from an excel sheet.
Below is the code for deleting multiple rows in a single activity.
for (int i = startRowIndexToDel; i <= endRowIndexToDel; i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
sheet.removeRow(row);
}
}
if (endRowIndexToDel < lastRowIndex) {
sheet.shiftRows(endRowIndexToDel + 1, lastRowIndex,
startRowIndexToDel - (endRowIndexToDel + 1));
}
The above code works okay when the rows that I need to delete do not have cell comments.
When they have cell comments, the comments stay behind and are assigned to rows that are shifted to the deleted row's place, which is not what I want.
Same is the case when I need to delete only one row and that happens to be the last row.
In that case, my code does not shift the rows since it is the last row.
I am aware of the fact that using removeRow() does not 'delete' the row, as happens when we right click on an excel row and choose delete, and instead clears the row of data as happens when we choose a row in excel and click on the delete keyboard button. I also noticed that the latter action also does not clear cell comments.
I would like to know if anyone else had noticed this issue and what was your fix for it. I can parse through all the cells in the row that I want to delete and remove cell comments if they are present, but I do not want to do this.

Reading Excel with some Borders missing

I am reading a .xslx file using Apache POI in Java.The last row in it is having some borders missing around some cells.
when I am reading this then in the last row after reading "abc"(written in first cell) ,am directly reading "rule1"(written in third cell) and second column is empty and bottom border is missing for it.
So the value of second cell which is empty cell is lost.So how can I be able to know that whether I have skipped any cell due to this formatting problem?
Use Cell.getColumnIndex() to retrieve the current cell's index. With this information you will be able to exactly get its position, and thus also find out whether there were any groups.

Setting Header Row in Itext Table

I am creating a table using itext. Now while setting header row, if I set table.setheaderrows(2) then it sets first 2 rows as the header. But in my case I want only row no. 2 (not row number 1) to be reprinted while table is extended on the next page.
Is there any way to achieve this?
If you only work with a single PdfPTable, you can't define the second row as the header row that needs to be repeated. The trick is to use two PdfPTable instances with the same widths for the columns. The first one would be a single row table for the first header row, the second one would start with the header row that needs to be repeated. If you add two tables to a document, one right after the other, they are glued to each other and nobody will notice that it's not a single table.

How to get total number of rows in swt.table

What i want to do is to get all the tableItems from the selected row. but i have find out that the tableItems are stored in indexes (like in arrary) and not like give row and column and store it on specific cell of table (row, column).
So i have to go through all the next rows upto the end of table and then go through all the rows upto the selected row to get to my required tableItem.
See image for clearance of my question. The coloured row is the selected one. If i want to go from 'a' to 'b' and then 'c' and so on for complete row, i have go through all the next rows.
so now the problem is how can i get the total number of rows present in swt.table
A SWT TableItem IS a row in your Table. You can use it's getText(int index) method to get the contents of the column with index (starting from 0 for the first column) of the selected TableItem.
Therefor the number of TableItems is the total number of rows.

Categories