How to use addMergedRegion apache poi?
I am trying to merge two columns of one row to make one long line of text without any vertical separation by the cell borders. Here's what I have so far:
CellRangeAddress mergedRegion = new CellRangeAddress(0,0,0,1); sheet.addMergedRegion(mergedRegion); XSSFRow row = sheet.createRow(mergedRegion.getFirstRow()); XSSFCell cell = row.createCell(mergedRegion.getFirstColumn()); cell.setCellValue("some string");
Is this the correct way to set the cells contents? In my Junits do I refer to this merged region like this:
assertEquals(workbook.getSheetAt(0).getRow(mergedRegion.getFirstRow()) .getCell(mergedRegion.getFirstColumn()).getStringCellValue(),"some string");
1 Answer
It is probably easier to set the cell contents before you create the merged region. So for example you could:
Row row = sheet.createRow(1); Cell cell = row.createCell(1); cell.setCellValue("some string"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 5));
This would add a merged region in columns 1-5 of row 1
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoa29uZ2mEdIOOoaawZaSkera%2FxGaYnZydmr%2BoscOrnKChn6N6orzAnJ%2BeZaCktg%3D%3D
Delta Gatti
Update: 2024-05-31