如何使用Apache POI获得单元格背景颜色? [英] How to get cell's background color using apache poi?

查看:1660
本文介绍了如何使用Apache POI获得单元格背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何获得背景颜色 XSSFCell 。我试着用 XSSFCellStyle ,但没有运气。

How do we get background color of a XSSFCell. I tried using XSSFCellStyle but no luck.

FileInputStream fis = new FileInputStream(fileName);
XSSFWorkbook book = new XSSFWorkbook(fis);
XSSFSheet sheet = book.getSheetAt(0);
XSSFRow row = sheet.getRow(0);

System.out.println(row.getCell(0).getCellStyle().getFillForegroundColor());

使用这些步骤我不能够得到底色再presentation在键入

Using these steps I am not able to get background color representation in Short type.

推荐答案

本结账网址:

https://issues.apache.org/bugzilla/show_bug.cgi? ID = 45492

Cell cell = row.getCell(1);
            CellStyle cellStyle = cell.getCellStyle();          
            System.out.println("color = " + getColorPattern(cellStyle.getFillForegroundColor()));




private short[] getColorPattern(short colorIdx){        
    short[] triplet = null;
    HSSFColor color = palette.getColor(colorIdx);
    triplet = color.getTriplet();       
    System.out.println("color : " + triplet[0] +"," + triplet[1] + "," + triplet[2]);
    return triplet;
}

这返回RGB codeS,但不准确的。但与在XLS自定义颜色选择器的实际颜色code相比,它或多或少相同颜色恢复。

This returns the RGB codes but not exact ones. But its more or less the same color returned when compared with the actual color code in the XLS custom color picker.

这篇关于如何使用Apache POI获得单元格背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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