栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

POI Excel:获取样式名称

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

POI Excel:获取样式名称

经过大量的挖掘,我找到了解决方案。我想我会在这里分享。我仍然没有找到样式的名称。但是我已经找到一种获得颜色的方法。

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];   }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596255.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号