gpt4 book ai didi

java - 将短路更改为颜色或其他方式

转载 作者:行者123 更新时间:2023-11-30 09:44:05 25 4
gpt4 key购买 nike

如何将颜色类型更改为 short 或 short to color?实际上,我正在使用 HSSFCellStyle 类的 setFillForegroundColor 方法。我需要将颜色传递给我的方法并使用该函数。但是,它需要 short 类型作为对象。
有什么方法可以将其更改为我需要的类型,或者是否有其他方法可以帮助我设置前景色?

因为我是从用户偏好中获取颜色,所以我以前不知道颜色。所以,我不能使用颜色索引。请给我一些建议。我的代码如下所示:

private void setBackgroudColorOfRow(HSSFWorkbook wb, HSSFRow row, Color bgColor) {
HSSFCell cell;
//Iterate through each cell and colour with light orange to
//differentiate the summary row with detail rows
for (Iterator it = row.cellIterator(); it.hasNext();) {
cell = (HSSFCell) it.next(); // row.getCell(j);
if(cell.getColumnIndex() > 1)
{
HSSFCellStyle style = wb.createCellStyle();
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(bgColor);

好的,让我重新构建我的问题或者更确切地说缩短它:

如果我在字符串中有颜色代码或者我有颜色名称,我如何获得颜色代码索引,我如何获得它的颜色代码索引?

最佳答案

style.setRightBorderColor(HSSFColor.BLACK.index);

请参阅此处以处理自定义颜色。

http://poi.apache.org/spreadsheet/quick-guide.html#CustomColors


//为工作簿创建自定义调色板 HSSFPalette 调色板 = wb.getCustomPalette();

//replacing the standard red with freebsd.org red
palette.setColorAtIndex(HSSFColor.RED.index,
(byte) 153, //RGB red (0-255)
(byte) 0, //RGB green
(byte) 0 //RGB blue
);

关于java - 将短路更改为颜色或其他方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8075981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com