我想读取应用于xlsx文档中单元格样式的名称。 我已提取的文件,并在XL/styles.xml我能找到的样式名称:POI Excel:获取样式名称
<cellStyles count="3">
<cellStyle xfId="2" builtinId="7" name="Currency [0]"/>
<cellStyle xfId="0" builtinId="0" name="Normal"/>
<cellStyle xfId="1" name="test style"/>
</cellStyles>
的风格名称,我想是“试验式”。目前,我有下面的代码,我可以得到xfId而不是名称:
@Override
public String getName(Workbook table, XSSFCell cell, String value) {
XSSFCellStyle cellStyle = cell.getCellStyle();
CellColor cellColor = new CellColor(cellStyle);
int xfId = cellStyle.getCoreXf().getFillId();
//todo: fint name, not xfId
return null;
}
有谁知道,如果我能得到的POI的风格名称,我怎么会去要呢?
如果这是不可能的,那么我可以得到基于xfId作为rgb的背景颜色?
关于
您是否试过[XSSFCellStyle getFillBackgroundColorColor方法?](https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFCellStyle.html#getFillBackgroundColorColor%28%29)。无法通过快速搜索找到获取名称的方法。 – 2014-10-31 13:05:50
我曾尝试过,但由于某些原因,在单元格上使用自定义格式时,使用此方法的颜色为null。 – 2014-10-31 13:11:07
有一件事可能会让你的颜色是如果风格索引在工作簿中。使用[getStylesSource](http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html#getStylesSource%28%29)从'table'获取'StylesTable'并查看您的CellStyle在那里,希望有填充背景颜色。 – 2014-10-31 13:27:16