如何使用 Apache POI 为整行应用粗体文本样式? [英] How to apply bold text style for an entire row using Apache POI?
本文介绍了如何使用 Apache POI 为整行应用粗体文本样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 Apache POI 将整个 excel 行单元格设为粗体文本?
How to make an entire excel row cells bold text using Apache POI?
例如:
列标题应为粗体.不是为标题行的每个单元格应用样式,我如何将某种样式应用到整行?
E.g:
Column headings should be in bold. Instead of applying style for each and every cell of heading row, how can I apply some style to an entire row?
推荐答案
这应该可以正常工作.
Workbook wb = new XSSFWorkbook("myWorkbook.xlsx");
Row row=sheet.getRow(0);
CellStyle style=null;
XSSFFont defaultFont= wb.createFont();
defaultFont.setFontHeightInPoints((short)10);
defaultFont.setFontName("Arial");
defaultFont.setColor(IndexedColors.BLACK.getIndex());
defaultFont.setBold(false);
defaultFont.setItalic(false);
XSSFFont font= wb.createFont();
font.setFontHeightInPoints((short)10);
font.setFontName("Arial");
font.setColor(IndexedColors.WHITE.getIndex());
font.setBold(true);
font.setItalic(false);
style=row.getRowStyle();
style.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFont(font);
如果您不创建 defaultFont
,您的所有工作簿都将使用另一个作为默认值.
If you do not create defaultFont
all your workbook will be using the other one as default.
这篇关于如何使用 Apache POI 为整行应用粗体文本样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文