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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.