import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import java.io.*; public class Sample2_1{ public static void main(String[] args){ Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row1 = sheet.createRow(1); Cell cell1_0 = row1.createCell(0); Cell cell1_1 = row1.createCell(1); Cell cell1_2 = row1.createCell(2); cell1_0.setCellValue("MAROON"); cell1_1.setCellValue("RED"); cell1_2.setCellValue("AQUA"); CellStyle style1 = wb.createCellStyle(); style1.setFillPattern(CellStyle.SOLID_FOREGROUND); style1.setFillForegroundColor(IndexedColors.MAROON.getIndex()); CellStyle style2 = wb.createCellStyle(); style2.setFillPattern(CellStyle.SOLID_FOREGROUND); style2.setFillForegroundColor(IndexedColors.RED.getIndex()); CellStyle style3 = wb.createCellStyle(); style3.setFillPattern(CellStyle.SOLID_FOREGROUND); style3.setFillForegroundColor(IndexedColors.AQUA.getIndex()); cell1_0.setCellStyle(style1); cell1_1.setCellStyle(style2); cell1_2.setCellStyle(style3); FileOutputStream out = null; try{ out = new FileOutputStream("sample2_1.xls"); wb.write(out); }catch(IOException e){ System.out.println(e.toString()); }finally{ try { out.close(); }catch(IOException e){ System.out.println(e.toString()); } } } }