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:
这是设置单元格内容的正确方法吗?在我的Junits中,我是这样引用这个合并的区域:
assertEquals(workbook.getSheetAt(0).getRow(mergedRegion.getFirstRow())
.getCell(mergedRegion.getFirstColumn()).getStringCellValue(),"some string");
1 个解决方案
#1
0
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
这将在第1行的第1-5列中添加合并区域
#1
0
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
这将在第1行的第1-5列中添加合并区域