如何使用java在excel中为特定单元格加粗

时间:2013-09-30 09:39:38

标签: java jxl

我可以知道如何在同一代码中使用粗体吗?我只需要一行粗体。我怎么能为它编写代码?

我的代码,

WritableFont cellFont = new WritableFont(WritableFont.TIMES,14);
cellFont.setBoldStyle(WritableFont.BOLD); 
WritableCellFormat cellFormat = new WritableCellFormat(cellFont);
cellFormat.setWrap(true); 
Label Sheet1cellContent = new Label(0,0,"LAST NAME",cellFormat);

1 个答案:

答案 0 :(得分:2)

参考Apache POI

HSSFFont boldFont = wb.createFont();
boldFont.setFontHeightInPoints((short)22);
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //Setting Bold font

HSSFCellStyle boldStyle = wb.createCellStyle();
boldStyle.setFont(boldFont); //Attaching the font to the Style

HSSFRow row = sheet1.createRow((short)1);
HSSFCell cell = row.createCell((short)0);
cell.setCellValue("This quick brown fox");
cell.setCellStyle(boldStyle); //Applying Style to the Cell.