poi-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Graham <v-chrisgra...@nbnco.com.au>
Subject Web Site Issues: FAQ #13: I am using styles when creating a workbook in POI, but Excel refuses to open the file, complaining about "Too Many Styles".
Date Fri, 23 Mar 2012 00:28:39 GMT
Hi All.

The sample provided, is broken.

Here's one that works.

-Chris

    private static void xlsSample() throws IOException
    {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("new sheet");
        HSSFRow row = sheet.createRow(0);

        // Aqua background
        HSSFCellStyle style = wb.createCellStyle();
        style.setFillBackgroundColor(HSSFColor.AQUA.index);
        style.setFillPattern(HSSFCellStyle.BIG_SPOTS);
        HSSFCell cell = row.createCell((short) 0);
        cell.setCellValue("X");
        cell.setCellStyle(style);

        // Orange "foreground",
        //     foreground being the fill foreground not the font color.
        style = wb.createCellStyle();
        style.setFillForegroundColor(HSSFColor.ORANGE.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        for (int x = 0; x < 10; x++)
        {

            // Create a row and put some cells in it. Rows are 0 based.
            row = sheet.createRow((short) x+1);

            for (int y = 0; y < 10; y++)
            {
                cell = row.createCell((short) y);
                cell.setCellValue("X");
                cell.setCellStyle(style);
            }
        }

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        wb.write(fileOut);
        fileOut.close();
    }



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message