[英]How to get background cell color in XSSF
I am using apache poi 3.9 in my project I need to get XSSF file cell background color. 我在我的项目中使用apache poi 3.9,我需要获取XSSF文件单元格背景色。
Workbook myWorkBook = WorkbookFactory.create(new File(filePath));
Sheet mySheet = myWorkBook.getSheetAt(0);
Row currentRow = null;
Iterator<Row> rowIterator = mySheet.iterator();
while (rowIterator.hasNext())
{
currentRow = (Row) rowIterator.next();
totalColumns = currentRow.getPhysicalNumberOfCells();
for (int column = 0; column < totalColumns; column++)
{
Cell cell = currentRow.getCell(column);
CellStyle cellStyle = cell.getCellStyle();
short colorIdx=cellStyle.getFillForegroundColor();
// I am struct in this step to get XSSF cell background color
}
}
In binary BIFF
( *.xls
) format ( HSSF
in apache poi
), colors can only be indexed colors from the color palette. 在二进制BIFF
( *.xls
)格式( apache poi
HSSF
)中,颜色只能是调色板中的索引颜色。
But in Office Open XML
( *.xlsx
) format ( XSSF
in apache poi
), colors can also be given in RGB
form. 但是在Office Open XML
( *.xlsx
)格式( apache poi
XSSF
)中,颜色也可以RGB
形式给出。 So in XSSF
not all colors will be indexed colors. 因此,在XSSF
并非所有颜色都是索引颜色。 That's why CellStyle.getFillForegroundColor returns 0 if the fill foreground color (the color of the fill pattern) is not an indexed color. 这就是为什么如果填充前景色(填充图案的颜色)不是索引颜色,则CellStyle.getFillForegroundColor返回0的原因。
Do using CellStyle.getFillForegroundColorColor in XSSF
. 请在XSSF
使用XSSF
。 This returns a Color which is a XSSFColor in XSSF
. 这将返回一个Color ,它是XSSF中的XSSF
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.