<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%> <%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%> <%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%> <%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%> <%@ page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%> <%@ page import="org.apache.poi.hssf.util.HSSFColor"%> <%@ page contentType="application/vnd.ms-excel" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <% try{ HSSFWorkbook hwb = new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet("new sheet"); HSSFCellStyle style1 = hwb.createCellStyle(); HSSFCellStyle style2 = hwb.createCellStyle(); HSSFCellStyle style3 = hwb.createCellStyle(); HSSFCellStyle style4 = hwb.createCellStyle(); HSSFCellStyle style = hwb.createCellStyle(); for(int i=0;i<50;i++){ HSSFRow row = sheet.createRow((short) 0+i); HSSFCell cell = row.createCell((short) 0); cell.setCellValue(1); style.setFillBackgroundColor(HSSFColor.AQUA.index); style.setFillPattern(HSSFCellStyle.BIG_SPOTS); style.setFillForegroundColor(HSSFColor.ORANGE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFCell cell4 = row.createCell((short) 1); cell4.setCellValue(2); HSSFCell cell1 = row.createCell((short) 2); cell1.setCellValue(3); HSSFCell cell2 = row.createCell((short) 3); cell2.setCellValue(4); HSSFCell cell3 = row.createCell((short) 4); cell3.setCellValue(5); style.setFillBackgroundColor(HSSFColor.AQUA.index); style.setFillPattern(HSSFCellStyle.BIG_SPOTS); style1.setFillForegroundColor(HSSFColor.ORANGE.index); style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setFillBackgroundColor(HSSFColor.RED.index); style2.setFillPattern(HSSFCellStyle.BIG_SPOTS); style3.setFillForegroundColor(HSSFColor.GREEN.index); style3.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style4.setFillForegroundColor(HSSFColor.BLUE.index); style4.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cell.setCellStyle(style); cell1.setCellStyle(style1); cell2.setCellStyle(style2); cell3.setCellStyle(style3); cell4.setCellStyle(style4); } FileOutputStream fileOut = new FileOutputStream("C:\\excel\\fillsColor.xls"); hwb.write(fileOut); fileOut.close(); out.println("Your excel file has been generated"); } catch ( Exception ex ) { } %>