Java Apache Poi,如何同时设置背景颜色和边框 [英] Java Apache Poi, how to set background color and borders at same time

查看:568
本文介绍了Java Apache Poi,如何同时设置背景颜色和边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一开始我想说我是开发人员领域的新手.

at start i want to say that i'm totally new in developers world.

我试图生成一个Excel表,该表包含带边框的Mutiplication表并设置背景颜色,但仅用于第一列和第一行.

I tried to generate an excel sheet that contains Mutiplication Table with borders and set background color but only for 1st column and row.

这是正确的示例:正确的示例

我写了类似的东西,但是结果文件中彩色单元格没有边框:(.

I wrote something like that, but in result file colored cells has not have borders :(.

请向我说明如何同时设置背景颜色和边框.

Please explain me how to set background color and borders at the same time.

推荐答案

backgroundStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex());更改为

 backgroundStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());

您可以按如下所示设置边框:

And you can set border as like below :

        backgroundStyle.setBorderBottom(CellStyle.BORDER_THIN);
        backgroundStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        backgroundStyle.setBorderLeft(CellStyle.BORDER_THIN);
        backgroundStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        backgroundStyle.setBorderRight(CellStyle.BORDER_THIN);
        backgroundStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
        backgroundStyle.setBorderTop(CellStyle.BORDER_THIN);
        backgroundStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

这将根据需要为您提供黄色和边框

This will give you yellow color and border as required

这篇关于Java Apache Poi,如何同时设置背景颜色和边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆