2013-09-30 127 views
-4

我可以知道如何在相同的代码中使用粗体?我只需要一行应该以粗体显示。我怎样才能为它编写代码?如何在excel中使用java加粗特定单元格

我的代码,

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); 
+0

安置自己尝试代码。 – newuser

+0

你试过了什么。邮政编码 –

+1

您是否可以为我们的要求添加一个模板excel [表格格式]?很容易给出反馈。 – Nagarajan

回答

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. 
+0

你能告诉我Jxl.I没有使用Apache POI –

+1

@Arun Kumar发布了你已经试过的代码和你的问题,这样用户很容易回答 – Woody

+0

WritableFont cellFont = new WritableFont(WritableFont.TIMES,14); \t cellFont.setBoldStyle(WritableFont.BOLD); \t WritableCellFormat cellFormat = new WritableCellFormat(cellFont); \t cellFormat.setWrap(true); \t Label Sheet1cellContent = new Label(0,0,“LAST NAME”,cellFormat);这是我的代码。这段代码的输出是完全粗体的。我需要第一行加粗。你能帮我吗? –

相关问题