Code is as follows, is there something wrong with it?
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row=sheet.createRow(0);
Font font= wb.createFont();
font.setBold(true);
CellStyle style = wb.createCellStyle();
style.setFont(font);
Cell cell = row.createCell(0);
cell.setCellValue("hello你好");
cell.setCellStyle(style);
try {
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("test.xlsx");
wb.write(fileOut);
fileOut.close();
}
catch (Exception e) {
System.out.print(e.getMessage());
}
I'm using Mac Numbers testing the generated excel file.
Note: The code abouve works when switch XSSFWorkbook
to HSSFWorkbook
.