导出excel修改样式

protected HSSFWorkbook workbook = null;
protected HSSFSheet curSheet = null;
protected HSSFRow curRow = null;
protected HSSFCellStyle curStyle = null;

excel合并单元格
//合并第r行的,从第2列开始,第三列结束,相当于合并第r行的第2列与第三列
this.curSheet.addMergedRegion( new Region( r, ( short )1, r, ( short )3 ) );

//合并第1列的,从第r行合并到第r+5行
this.curSheet.addMergedRegion( new Region( r, ( short )0, r + 5, ( short )0 ) );

//修改样式
//修改excel下边框大小为0
this.curStyle.setBorderBottom((short)0);
//修改excel左边框大小为0
this.curStyle.setBorderLeft((short)0);

//单元格内容换行

强制换行 直接加"\n"
HSSFCellStyle style = workbook.createCellStyle();
style.setWrapText(true);//自动换行


//10号字体,带边框,垂直居中
public HSSFCellStyle twFourLineCenter( HSSFWorkbook workbook ){
HSSFCellStyle style = workbook.createCellStyle();
HSSFFont font = workbook.createFont(); //定义字体
font.setFontName( "宋体" );
font.setFontHeightInPoints( ( short )10 );
font.setBoldweight( ( short )1000000 );
style.setFont( font );
style.setBorderBottom( HSSFCellStyle.BORDER_THIN );
style.setBottomBorderColor( HSSFColor.BLACK.index );
style.setBorderLeft( HSSFCellStyle.BORDER_THIN );
style.setLeftBorderColor( HSSFColor.BLACK.index );
style.setBorderRight( HSSFCellStyle.BORDER_THIN );
style.setRightBorderColor( HSSFColor.BLACK.index );
style.setBorderTop( HSSFCellStyle.BORDER_THIN );
style.setTopBorderColor( HSSFColor.BLACK.index );
style.setVerticalAlignment( HSSFCellStyle.VERTICAL_CENTER );
style.setAlignment( HSSFCellStyle.ALIGN_CENTER );
style.setWrapText(true);
return style;

}

//设置exce行为黄色背景
this.curStyle=rowLineStyle(this.workbook);

/**
* 定义行样式
* @param workbook
* @return
*/
public HSSFCellStyle rowLineStyle( HSSFWorkbook workbook ){
HSSFCellStyle style = workbook.createCellStyle();
HSSFFont font = workbook.createFont();
font.setFontHeightInPoints( ( short )10 );
font.setFontName( "宋体" );
font.setItalic( false );
font.setStrikeout( false );
font.setBoldweight( ( short )1000000 );
style.setFont( font );
// style.setFillBackgroundColor(HSSFColor.YELLOW.index);
style.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index); //填充的背景颜色
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(HSSFColor.YELLOW.index); style.setVerticalAlignment( HSSFCellStyle.VERTICAL_CENTER );
style.setAlignment( HSSFCellStyle.ALIGN_LEFT );
style.setBorderRight((short)1);
style.setWrapText(true);
return style;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值