[1 个单元格中的文本]
ABC(粉红色)
DEF(黑色)
GHI(红色)
我必须像上面那样检查单元格中文本的字体颜色。
(抱歉,我无法上传图片)
第一行的颜色是粉红色。
下一行的颜色是黑色和红色。
如您所见,我无法使用 getCellStyle() 方法,因为单元格有 3 个字体属性。
我输入了如下所示的源代码。
XSSFCell cell = row.getCell(0);
XSSFRichTextString value = cell.getRichStringCellValue();
String[] info = value.getString().split("\n");
for(int i = 0; i < info.length; i++) {
int index = value.getString().indexOf(info);
System.out.println(value.getFontAtIndex(index).getColor());
}
但是,我没有得到正确的结果。
我想知道如何获取每个文本的字体信息。
请告诉我您的宝贵建议。
非常感谢。
祝你有美好的一天!
尝试以下操作:它会起作用
public static void differentColorInSingleCell(){
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
Cell cell = sheet.createRow(0).createCell(0);
Font Font1 = wb.createFont();
Font1.setColor(HSSFColor.RED.index);
Font Font2 = wb.createFont();
Font2.setColor(HSSFColor.BLUE.index);
CellStyle style = wb.createCellStyle();
style.setFont(Font1);
cell.setCellStyle(style);
RichTextString richString = new HSSFRichTextString("RED, BLUE");
richString.applyFont(4, 9, Font2);
cell.setCellValue(richString);
//Write the file Now
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)