In below code, I intend to have "Jack Reacher" in bold style and the rest of the string as normal font. I am not able to see the newline appended in report after "Jack Reacher". Newline gets applied if I comment and ignore bold descEntryRichStr.applyFont(0, name.length() , boldedFont);
I have added cs.setWrapText(true);
also but it still doesnt work
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Test First");
XSSFFont boldedFont = workbook.createFont();
boldedFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
String newLine = "\n";
String name = "Jack Reacher";
String fileNo = "Professsion : Doctor";
String other = "Address : New-york" ;
String finalString = name +newLine + fileNo + newLine + other;
Row row = sheet.createRow(0);
XSSFCell cell = (XSSFCell) row.createCell(0);
CreationHelper creationHelper = workbook.getCreationHelper();
XSSFRichTextString descEntryRichStr = (XSSFRichTextString) creationHelper.createRichTextString(finalString);
descEntryRichStr.applyFont(0, name.length() , boldedFont);
cell.setCellValue(descEntryRichStr);
XSSFCellStyle cs = cell.getCellStyle();
cs.setWrapText(true);
cell.setCellStyle(cs);
System.out.println(cell.getStringCellValue());
try (FileOutputStream outputStream = new FileOutputStream("/shared/sample/report-"+new Date().getTime() +".xlsx")) {
workbook.write(outputStream);
}