NOPI用法之自定义单元格背景色(2)

文章提供了两种使用XSSFCellStyle在Java中设置Excel单元格背景色的方法。方法1直接设置RGB值,方法2则涉及对齐方式、边框样式和文本换行的配置,最后均使用SolidForeground填充模式来设定颜色。
摘要由CSDN通过智能技术生成

俩种设置单元格背景色的方法

//方法1
XSSFCellStyle rowsStyleColor = (XSSFCellStyle)xssfworkbook.CreateCellStyle();
XSSFColor xssfColor = new XSSFColor();
//根据自己需要设置RGB
byte[] colorRgb = { (byte)252, (byte)139, (byte)139 };
xssfColor.SetRgb(colorRgb);
rowsStyleColor.FillForegroundColorColor = xssfColor;
rowsStyleColor.FillPattern = FillPattern.SolidForeground;


//方法2
ICellStyle rowsStyleColor = (XSSFCellStyle)xssfworkbook.CreateCellStyle();
rowsStyleColor.Alignment = HorizontalAlignment.Center;
rowsStyleColor.VerticalAlignment = VerticalAlignment.Center;
rowsStyleColor.BorderBottom = BorderStyle.Thin;
rowsStyleColor.BorderLeft = BorderStyle.Thin;
rowsStyleColor.BorderRight = BorderStyle.Thin;
rowsStyleColor.BorderTop = BorderStyle.Thin;
rowsStyleColor.WrapText = true;
//设置背景颜色...
rowsStyleColor.FillForegroundColor = 0;
rowsStyleColor.FillPattern = FillPattern.SolidForeground;
((XSSFColor)rowsStyleColor.FillForegroundColorColor).SetRgb(new byte[] { 252, 139, 139 });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值