我试图在excel表中添加一些样式,我使用apache poi生成。这是代码,我试图在BOLD中创建第一行。
SXSSFWorkbook wb=new SXSSFWorkbook();
Sheet sheet = wb.createSheet("Excelx");
Row row= sheet.createRow((short)0);
row.createCell((short) 0).setCellValue("SRNum");
row.createCell((short) 1).setCellValue("Name");
CellStyle cs = wb.createCellStyle();
Font f = wb.createFont();
f.setFontHeightInPoints((short) 20);
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
cs.setFont(f);
row.setRowStyle(cs);
但是,第一行仍未改为BOLD。
答案 0 :(得分:7)
根据Gagravarr的宝贵意见,我更改了代码:
Row rowhead= sheet.createRow((short)0);
Font f = wb.createFont();
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
CellStyle cs = wb.createCellStyle();
cs.setFont(f);
Cell cell;
cell = rowhead.createCell((short) 0);
cell.setCellValue("SRNum");
cell.setCellStyle(cs);
cell = rowhead.createCell((short) 1);
cell.setCellValue("Name");
cell.setCellStyle(cs);