经过大量的挖掘,我找到了解决方案。我想我会在这里分享。我仍然没有找到样式的名称。但是我已经找到一种获得颜色的方法。
CellStyle有一个xf对象,该对象保存了所用填充的参考索引。您可以从“工作簿样式表”中获取填充。
填充根据颜色是不同的来引用颜色。它只是具有您可以解析的rgb字符串,或者具有主题ID和色调值。
您可以像填充一样从StylesTable中获取主题。并且该主题具有rgb值。我不确定如何应用色调,但是在我的测试中并没有必要。
private int red;private int green;private int blue;public void loadRgb(XSSFWorkbook table, XSSFCellStyle variableStyle) { long fillId = variableStyle.getCoreXf().getFillId(); StylesTable stylesSource = table.getStylesSource(); XSSFCellFill fill = stylesSource.getFillAt((int) fillId); CTColor fgColor = fill.getCTFill().getPatternFill().getFgColor(); if (fgColor != null) { if (fgColor.xgetRgb() != null) { convert(fgColor.xgetRgb().getStringValue()); } else { convert(stylesSource.getTheme().getThemeColor((int) fgColor.getTheme()).getRgb()); } }}private void convert(String stringValue) { // the string value contains an alpha value, so we skip the first 2 chars red = Integer.valueOf(stringValue.substring(2, 4), 16).intValue(); green = Integer.valueOf(stringValue.substring(4, 6), 16).intValue(); blue = Integer.valueOf(stringValue.substring(6, 8), 16).intValue();}private void convert(byte[] rgb) { if (rgb != null) { // Bytes are signed, so values of 128+ are negative! // 0: red, 1: green, 2: blue red = (rgb[0] < 0) ? (rgb[0] + 256) : rgb[0]; green = (rgb[1] < 0) ? (rgb[1] + 256) : rgb[1]; blue = (rgb[2] < 0) ? (rgb[2] + 256) : rgb[2]; }}


