如何获取给定单元格的(Java Apache POI HSSF)背景颜色? [英] How do I get the (Java Apache POI HSSF) Background Color for a given cell?

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

问题描述

我有一个现有的 excel 电子表格,我正在从中访问和读取值,我正在使用 Apache POI HSSF.

I have an existing excel spreadsheet, which I am accesssing and reading values from, I am using Apache POI HSSF.

初始化如下:

HSSFSheet sheet;
FileInputStream fis = new FileInputStream(this.file);
POIFSFileSystem fs = new POIFSFileSystem(fis);
HSSFWorkbook wb = new HSSFWorkbook(fs);
this.sheet = wb.getSheet(exsheet);

我正在遍历工作表中存在的所有单元格,这构成了一个单元格对象:

I am iterating over all the cells that exist in the sheet, which makes a cell object:

HSSFCell cell = (HSSFCell) cells.next();

请熟悉框架的人解释一下如何创建一个 (HSSFColor) 对象来表示工作表中每个单元格的背景颜色.

Please can someone familiar with the framework explain how to create an (HSSFColor) object to represent the backround color of each cell in the sheet.

非常感谢

编辑、更新

要清楚我想知道的是:如何为现有单元格的背景色创建/获取 HSSFColor 对象?

To be clear what I want to know is: how do I create/get an HSSFColor object for the background color of an existing cell?

cell.getCellStyle().getFillBackgroundColor(); 

这段代码只返回一个短数字,而不是一个 HSSFColor 对象.感谢您到目前为止的回答.

This code only returns a short number, not an HSSFColor object. Thanks for the answers so far.

推荐答案

有 HSSFCell 类提供的静态颜色类,这里列出:

There are static color classes provided by the HSSFCell class, listed here:

http://poi.apache.org/apidocs/org/apache/poi/hssf/util/HSSFColor.html

如果您想创建自己的自定义颜色,则需要创建和修改自定义调色板.Apache 也为此提供了非常清晰的指南:

If you want to create your own custom colors, you will need to create and modify a custom palette. Apache provides a very clear guide to this as well:

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

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

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