poi解析excel文件,xssf的字体以及字体颜色处理

一个简单的测试用例,用来解析xlsx文件获取字体颜色


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;


import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;





public class testReadExcel {
	public static void readExcel () throws Exception {
	String path = "d:\\字体颜色1.xlsx";
	File file = new File(path);
	InputStream is = new FileInputStream(file);
	Workbook wb = new XSSFWorkbook(is);
	int numbersheets = wb.getNumberOfSheets();
	Sheet sheet = wb.getSheetAt(0);
	int cols = sheet.getPhysicalNumberOfRows();
	for(int i = 0; i=8) {
			str = str.substring(2, 8);
		}
		sb.append(str);
		return sb.toString();
	}
	
	public static void main(String[] args) throws Exception{
		readExcel();
	}
}


你可能感兴趣的:(eclipse,poi)