java hssffont_Java HSSFWorkbook.createFont方法代码示例

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类

private Map createHSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor,

int[] headerFontColor, int headerFontSize, int headerAlign) {

Map styles = new HashMap();

HSSFWorkbook workbook = (HSSFWorkbook) wb;

HSSFPalette palette = workbook.getCustomPalette();

palette.setColorAtIndex((short) 11, (byte) contextBgColor[0], (byte) contextBgColor[1], (byte) contextBgColor[2]);

palette.setColorAtIndex((short) 12, (byte) contextFontColor[0], (byte) contextFontColor[1], (byte) contextFontColor[2]);

palette.setColorAtIndex((short) 13, (byte) headerBgColor[0], (byte) headerBgColor[1], (byte) headerBgColor[2]);

palette.setColorAtIndex((short) 14, (byte) headerFontColor[0], (byte) headerFontColor[1], (byte) headerFontColor[2]);

HSSFFont headerFont = workbook.createFont();

headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET);

headerFont.setFontName("宋体");

headerFont.setColor((short) 14);

headerFont.setBold(true);

headerFont.setFontHeightInPoints((short) headerFontSize);

CellStyle headerStyle = this.createBorderCellStyle(workbook, true);

headerStyle.setFont(headerFont);

headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

headerStyle.setFillForegroundColor((short) 13);

this.setCellStyleAligment(headerStyle, headerAlign);

headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);

styles.put(GridStyleType.headerStyle.name(), headerStyle);

HSSFFont dataFont = workbook.createFont();

dataFont.setColor((short) 12);

dataFont.setFontHeightInPoints((short) contextFontSize);

dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET);

dataFont.setFontName("宋体");

CellStyle dataAlignLeftStyle = this.createBorderCellStyle(workbook, true);

dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

dataAlignLeftStyle.setFillForegroundColor((short) 11);

dataAlignLeftStyle.setFont(dataFont);

dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER);

dataAlignLeftStyle.setWrapText(true);

dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT);

styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle);

CellStyle dataAlignCenterStyle = this.createBorderCellStyle(workbook, true);

dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

dataAlignCenterStyle.setFillForegroundColor((short) 11);

dataAlignCenterStyle.setFont(dataFont);

dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER);

dataAlignCenterStyle.setWrapText(true);

dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER);

styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle);

CellStyle dataAlignRightStyle = this.createBorderCellStyle(workbook, true);

dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

dataAlignRightStyle.setFillForegroundColor((short) 11);

dataAlignRightStyle.setFont(dataFont);

dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER);

dataAlignRightStyle.setWrapText(true);

dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT);

styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle);

CellStyle dateStyle = this.createBorderCellStyle(workbook, true);

CreationHelper helper = workbook.getCreationHelper();

dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm"));

dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

dateStyle.setFillForegroundColor((short) 11);

dateStyle.setFont(dataFont);

dateStyle.setVerticalAlignment(VerticalAlignment.CENTER);

this.setCellStyleAligment(dateStyle, contextFontAlign);

styles.put(GridStyleType.dateStyle.name(), dateStyle);

return styles;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值