Hi,
I tried the below code
public void testMultiMergeRegions() throws IOException {
int currentStartRow = 5;
int currentStartColumn = 0;
Row row = null;
Cell sideQuestionCell = null;
HSSFFont redFont = null;
HSSFFont font = null;
HSSFCellStyle xResponseWithTopBorder = null;
HSSFCellStyle xResponseWithoutTopBorder = null;
String xAxisQuestion = "We Are Trying to replicate the problem
here";
Response response = new Response();
response.setId("1");
response
.setValue("Always have breakthroughs on
appearance and functions");
List<Response> xAxisResponseList = new ArrayList<Response>();
for (int i = 0; i < 20; i++) {
xAxisResponseList.add(response);
}
// initialising style here
font = workbook.createFont();
font.setColor(HSSFColor.BLACK.index);
redFont = workbook.createFont();
redFont.setColor(Font.COLOR_RED);
xResponseWithTopBorder = workbook.createCellStyle();
xResponseWithTopBorder.setWrapText(true);
xResponseWithTopBorder.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
xResponseWithTopBorder.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
xResponseWithTopBorder.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
xResponseWithTopBorder.setAlignment(HSSFCellStyle.ALIGN_LEFT);
xResponseWithTopBorder.setFillForegroundColor(HSSFColor.WHITE.index);
xResponseWithTopBorder.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
xResponseWithTopBorder.setLocked(false);
xResponseWithTopBorder.setFont(font);
xResponseWithoutTopBorder = workbook.createCellStyle();
xResponseWithoutTopBorder.setWrapText(true);
xResponseWithoutTopBorder.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
xResponseWithoutTopBorder
.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
xResponseWithoutTopBorder.setAlignment(HSSFCellStyle.ALIGN_LEFT);
xResponseWithoutTopBorder.setFillForegroundColor(HSSFColor.WHITE.index);
xResponseWithoutTopBorder
.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
xResponseWithoutTopBorder.setLocked(false);
xResponseWithoutTopBorder.setFont(font);
sideQuestionCell = sheet.createRow(currentStartRow).createCell(
currentStartColumn + 4);
//
sheet.getRow(currentStartRow).setHeightInPoints(sheet.getDefaultRowHeightInPoints());
CellRangeAddress cellXRange = new
CellRangeAddress(currentStartRow,
currentStartRow, currentStartColumn + 4,
((currentStartColumn + 4) +
xAxisResponseList.size()));
sheet.addMergedRegion(cellXRange);
setStyleMergedRegion(cellXRange, false, false, false, false,
true);
row = sheet.createRow(currentStartRow + 1);
sheet.getRow(currentStartRow).setHeightInPoints(
sheet.getDefaultRowHeightInPoints());
sheet.getRow(currentStartRow + 1).setHeightInPoints(
sheet.getDefaultRowHeightInPoints());
row = sheet.createRow(currentStartRow + 1);
sheet.setColumnWidth(currentStartRow + 1,
xAxisResponseList.size() + 1);
sideQuestionCell.setCellValue(xAxisQuestion);
sideQuestionCell.setCellStyle(xResponseWithoutTopBorder);
for (int indx = 0; indx < xAxisResponseList.size(); indx++) {
String xAxisRepsonse =
xAxisResponseList.get(indx).getValue();
Cell sideQuestionResponseCell =
row.createCell(currentStartColumn
+ 4 + indx);
sideQuestionResponseCell.setCellValue(xAxisRepsonse);
sideQuestionResponseCell.setCellStyle(xResponseWithTopBorder);
}
FileOutputStream out = new FileOutputStream("MergedRegion.xls");
workbook.write(out);
out.close();
}
but the problem is not solved.
Interestingly when the number of columns is less(upto 17 in the above case)
this behavior is not visible.
Any help will be appreciated.
dgv123 wrote:
>
> or try
>
> sheet.getRow(int
> rownum).setHeightInPoints(sheet.getDefaultRowHeightInPoints());
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://www.nabble.com/Autosize-row-for-HSSF-library-tp24132911p24209674.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]