需要读取xlsx文件(excel 2007及以上版本)
采用了POI 3.2包
想问一下,怎么才能获取到当前单元格的字体颜色,因为自己测试了一段时间,发现获取的颜色都是0.代码如下List<Account> list = new ArrayList<Account>();
Workbook book = null;
Cell cell = null;
try {
book = new XSSFWorkbook(path);
Sheet sheet = book.getSheet(sheetName);
int rows = 0;
rows = sheet.getPhysicalNumberOfRows(); for (int i = 1 ; i < rows ; i ++){
Row row = sheet.getRow(i);
cell = row.getCell(0);
CellStyle eStyle = cell.getCellStyle();
Font eFont = book.getFontAt(eStyle.getFontIndex());
String accountName = cell.getStringCellValue();
//Color = ExcelLoader.getFrontColor(book, cell);
System.out.println("accountName:"+accountName);
System.out.println("eFont.getColor();-"+eFont.getColor());在excel中,某一条的字体颜色是红色的,但是使用eFont.getColor()返回的值都是0请帮忙解决一下这个疑惑,谢谢!
采用了POI 3.2包
想问一下,怎么才能获取到当前单元格的字体颜色,因为自己测试了一段时间,发现获取的颜色都是0.代码如下List<Account> list = new ArrayList<Account>();
Workbook book = null;
Cell cell = null;
try {
book = new XSSFWorkbook(path);
Sheet sheet = book.getSheet(sheetName);
int rows = 0;
rows = sheet.getPhysicalNumberOfRows(); for (int i = 1 ; i < rows ; i ++){
Row row = sheet.getRow(i);
cell = row.getCell(0);
CellStyle eStyle = cell.getCellStyle();
Font eFont = book.getFontAt(eStyle.getFontIndex());
String accountName = cell.getStringCellValue();
//Color = ExcelLoader.getFrontColor(book, cell);
System.out.println("accountName:"+accountName);
System.out.println("eFont.getColor();-"+eFont.getColor());在excel中,某一条的字体颜色是红色的,但是使用eFont.getColor()返回的值都是0请帮忙解决一下这个疑惑,谢谢!
我在使用xls,即将excel转换为97-03版本的时候
使用eFont.getColor()返回值正常了,
红色的返回8,黑色的返回0求助.哈哈~~~
谢谢Jushi我看了一下你发出的链接,但是发现里面还是没有我需要的东西
链接里面有写获取字体和获取背景色
但还是没有当前文字的颜色~~
eFont.getColor()改为eFont.getIndex()即可~~
get the color for the font
以上是poi的api文档 这个方法没有错的
是啊,你说的对..
但是我的excel是xlsx格式的,使用getColor()一点反应都没有
用xls格式的,用getColor()是可以获取的...搞不懂啊搞不懂~~