I generated excel document from Postgres database, using POI API. The first column "Ordre" have many same values. However i want to merge this cells having the same values.
I want follow this algorithm :
- loop through the field "ordre"
- put a condition if cell(i) = cell(i+1)
- than merge them
But i have a problem with a condition how to say that (cell(i) = cell(i+1))
in Java, i'm not keen if it can give some satisfactory result
i started to write this code :
for (i=3; i<= sheet1.getPhysicalNumberOfRows() ; i++) {
Cell cell = sheet1.getRow(i).getCell(0);
if (sheet1.getRow(i).getCell(0).getStringCellValue() == sheet1.getRow(i+1).getCell(0).getStringCellValue())
{
CellRangeAddress cellRangeAddress = new CellRangeAddress(i,i+1,0,0);
sheet1.addMergedRegion(cellRangeAddress);
}
}
Any suggestion will be appreciated
use
Example:
"=="
is for reference equality check.equals()
method will be used to check contents equality.