Example usage for org.apache.poi.ss.usermodel IndexedColors WHITE

List of usage examples for org.apache.poi.ss.usermodel IndexedColors WHITE

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel IndexedColors WHITE.

Prototype

IndexedColors WHITE

To view the source code for org.apache.poi.ss.usermodel IndexedColors WHITE.

Click Source Link

Usage

From source file:DSC.QuantityReport.java

private static void processQuantityReport() {

    int excelNumber = 0;
    int sheetNumber = 0;
    workbook = new XSSFWorkbook();
    Map<String, String[]> data = new TreeMap<>();
    data.put(0 + "", new String[] { "Doorstep Chef - Quantity Report " + currentWeek(), "", "",
            "Week : " + returnWeekInt() + " " + " " });
    data.put(1 + "", new String[] { "", "", "", "", "", "", "" });
    data.put(2 + "", new String[] { "Total Of ", "Single", "Couple", "Three", "Four", "Five", "Six", "Extra" });

    XSSFSheet sheet = workbook.createSheet("Quantity Report " + sheetNumber);
    int rowNum = 0;
    int cellNum = 0;

    for (int i = 3; i < 19; i++) {
        if (i == 3) {
            data.put(i + "",
                    new String[] { "Orders", quantityObj.getCountFamilySize_1() + "",
                            quantityObj.getCountFamilySize_2() + "", quantityObj.getCountFamilySize_3() + "",
                            quantityObj.getCountFamilySize_4() + "", quantityObj.getCountFamilySize_5() + "",
                            quantityObj.getCountFamilySize_6() + "",
                            quantityObj.getCountFamilySizeMoreThanSix() + "" });
        } else if (i == 4) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 5) {
            data.put(i + "", new String[] { "Meals", quantityObj.getQuantityFamSize1() + "",
                    quantityObj.getQuantityFamSize2() + "", quantityObj.getQuantityFamSize3() + "",
                    quantityObj.getQuantityFamSize4() + "", quantityObj.getQuantityFamSize5() + "",
                    quantityObj.getQuantityFamSize6() + "", quantityObj.getQuantityFamSizeMoreThanSix() + "" });
        } else if (i == 6) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 7) {
            data.put(i + "", new String[] { "Standard Meals", quantityObj.getCountFamSize1_Standard() + "",
                    quantityObj.getCountFamSize2_Standard() + "", quantityObj.getCountFamSize3_Standard() + "",
                    quantityObj.getCountFamSize4_Standard() + "", quantityObj.getCountFamSize5_Standard() + "",
                    quantityObj.getCountFamSize6_Standard() + "",
                    quantityObj.getCountFamilySizeMoreThanSix_Standard() + "" });
        } else if (i == 8) {
            data.put(i + "",
                    new String[] { "Low Carb Meals", quantityObj.getCountFamSize1_LC() + "",
                            quantityObj.getCountFamSize2_LC() + "", quantityObj.getCountFamSize3_LC() + "",
                            quantityObj.getCountFamSize4_LC() + "", quantityObj.getCountFamSize5_LC() + "",
                            quantityObj.getCountFamSize6_LC() + "",
                            quantityObj.getCountFamilySizeMoreThanSix_LC() + "" });
        } else if (i == 9) {
            data.put(i + "",
                    new String[] { "Kiddies Meals", quantityObj.getCountFamSize1_KD() + "",
                            quantityObj.getCountFamSize2_KD() + "", quantityObj.getCountFamSize3_KD() + "",
                            quantityObj.getCountFamSize4_KD() + "", quantityObj.getCountFamSize5_KD() + "",
                            quantityObj.getCountFamSize6_KD() + "",
                            quantityObj.getCountFamilySizeMoreThanSix_KD() + "" });
        } else if (i == 10) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 11) {
            data.put(i + "",
                    new String[] { "Totals", quantityObj.totalSingleMeals() + "",
                            quantityObj.totalCoupleMeals() + "", quantityObj.totalThreeMeals() + "",
                            quantityObj.totalFourMeals() + "", quantityObj.totalFiveMeals() + "",
                            quantityObj.totalSixMeals() + "", quantityObj.totalExtraMeals() + "" });
        } else if (i == 12) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 13) {
            data.put(i + "", new String[] { "Standard Individuals", "", "", "", "", "", "",
                    quantityObj.returnTotalStandardMeals() + "" });
        } else if (i == 14) {
            data.put(i + "", new String[] { "Low Carb Individuals", "", "", "", "", "", "",
                    quantityObj.returnTotalLowCarbMeals() + "" });
        } else if (i == 15) {
            data.put(i + "", new String[] { "Kiddies Individuals", "", "", "", "", "", "",
                    quantityObj.returnTotalKiddiesMeals() + "" });
        } else if (i == 16) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 17) {
            data.put(i + "", new String[] { "Total Clients", "", "", "", "", "", "",
                    quantityObj.returnTotalClients() + "" });
        } else if (i == 18) {

            int totalIndividuals = quantityObj.returnTotalStandardMeals()
                    + quantityObj.returnTotalLowCarbMeals() + quantityObj.returnTotalKiddiesMeals();

            data.put(i + "",
                    new String[] { "Total Individuals", "", "", "", "", "", "", totalIndividuals + "" });
        }/* ww w  .  ja  v a 2s.c  o  m*/
    }

    Set<String> keySet = data.keySet();

    for (int keyIterate = 0; keyIterate < keySet.size(); keyIterate++) {
        Row row = sheet.createRow(rowNum);
        Object[] arr = data.get(keyIterate + "");
        XSSFCellStyle borderStyle = workbook.createCellStyle();
        XSSFCellStyle borderStyle2 = workbook.createCellStyle();
        for (int i = 0; i < arr.length; i++) {
            XSSFFont font = workbook.createFont();
            Cell cell = row.createCell(i);
            cell.setCellValue((String) arr[i]);

            if ((keyIterate + "").equals("0") || (keyIterate + "").equals("1")) {

                font.setFontName("Calibri");
                font.setFontHeightInPoints((short) 13);
                font.setBold(true);
                borderStyle.setFont(font);
                borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setAlignment(HorizontalAlignment.LEFT);

            } else if (keyIterate > 1 && keyIterate < 12) {
                borderStyle.setBorderBottom(BorderStyle.THIN);
                borderStyle.setBorderTop(BorderStyle.THIN);
                borderStyle.setBorderLeft(BorderStyle.THIN);
                borderStyle.setBorderRight(BorderStyle.THIN);

            }

            if ((keyIterate + "").equals("2")) {
                borderStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setAlignment(HorizontalAlignment.CENTER);
                borderStyle.setFillPattern(XSSFCellStyle.LESS_DOTS);
                borderStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
                XSSFFont font2 = workbook.createFont();
                font2.setColor(IndexedColors.WHITE.getIndex());
                borderStyle.setFont(font2);

            }

            cell.setCellStyle(borderStyle);
        }

        rowNum++;
        cellNum++;
        sheetNumber++;
    }

    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

    for (int i = 0; i < 8; i++) {
        if (i == 0) {
            sheet.setColumnWidth(i, 5000);
        } else {
            sheet.setColumnWidth(i, 2000);

        }

    }

    try {
        creatSheet(sheetNumber + "", workbook);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "File Could Not Be Found.");
    }

    excelNumber++;

}

From source file:ec.sirec.web.impuestos.GestionAlcabalasControlador.java

public void postProcessXLS(Object document) {
    XSSFWorkbook wb = (XSSFWorkbook) document;
    XSSFSheet sheet = wb.getSheetAt(0); //Creo variable  hoja ()contiene los atributos para la hoja de calculo
    List<String> encabezadoColumna = new ArrayList<String>();
    for (Row row : sheet) { //Recorre los valores de la fila 1 (encabezado) pero en dataTable=0
        if (row.getRowNum() == 0) {
            for (Cell cell : row) {
                encabezadoColumna.add(cell.getStringCellValue() + " ");
            }//from   w  ww. jav  a 2 s.c om
        } else {
            break;
        }
    }
    //----inicio crea estilo
    XSSFCellStyle style = wb.createCellStyle(); //Se crea el estilo
    XSSFFont font = wb.createFont();
    font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(font);
    byte[] rgb = new byte[3];
    rgb[0] = (byte) 076;
    rgb[1] = (byte) 145;
    rgb[2] = (byte) 065;
    XSSFColor myColor = new XSSFColor(rgb);
    style.setFillForegroundColor(myColor);
    style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    XSSFRow row0 = sheet.createRow((short) 0); //Creo una fila en la posicion 0
    //----fin crea estilo
    for (int i = 0; i <= encabezadoColumna.size() - 1; i++) {
        createCell(row0, i, encabezadoColumna.get(i), style); //agrego celdas en la posicion indicada con los valores de los encabezados
    }
    //Ajusta el ancho de las columnas
    for (int i = 0; i < 20; i++) {
        sheet.autoSizeColumn((short) i);
    }
}

From source file:edu.casetools.rcase.extensions.excel.control.Exporter.java

License:Open Source License

private void createHeaderStyle() {
    headerCellStyle = workbook.createCellStyle();
    headerCellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
    headerCellStyle.setFillPattern((short) 1);
    headerCellStyle.setWrapText(false);/*from www . j a  va 2  s.  co  m*/
    Font headerFont = workbook.createFont();
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    headerFont.setBoldweight((short) 700);
    headerCellStyle.setFont(headerFont);

    headerCellStyle.setBorderBottom((short) 1);
    headerCellStyle.setBottomBorderColor(IndexedColors.WHITE.getIndex());
    headerCellStyle.setBorderLeft((short) 1);
    headerCellStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex());
    headerCellStyle.setBorderRight((short) 1);
    headerCellStyle.setRightBorderColor(IndexedColors.WHITE.getIndex());
    headerCellStyle.setBorderTop((short) 1);
    headerCellStyle.setTopBorderColor(IndexedColors.WHITE.getIndex());
}

From source file:edu.casetools.rcase.extensions.excel.control.Exporter.java

License:Open Source License

private void createContentStyle() {
    contentCellStyle = workbook.createCellStyle();
    contentCellStyle.setVerticalAlignment((short) 0);
    contentCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
    contentCellStyle.setFillPattern((short) 1);
    this.contentCellStyle.setWrapText(true);

    this.contentCellStyle.setBorderBottom((short) 1);
    this.contentCellStyle.setBottomBorderColor(IndexedColors.WHITE.getIndex());
    this.contentCellStyle.setBorderLeft((short) 1);
    this.contentCellStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex());
    this.contentCellStyle.setBorderRight((short) 1);
    this.contentCellStyle.setRightBorderColor(IndexedColors.WHITE.getIndex());
    this.contentCellStyle.setBorderTop((short) 1);
    this.contentCellStyle.setTopBorderColor(IndexedColors.WHITE.getIndex());
}

From source file:edu.casetools.rcase.extensions.excel.control.Exporter.java

License:Open Source License

private void createElementNameStyle() {
    this.elementNameCellStyle = this.workbook.createCellStyle();
    this.elementNameCellStyle.setVerticalAlignment((short) 0);
    this.elementNameCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
    this.elementNameCellStyle.setFillPattern((short) 1);
    this.elementNameCellStyle.setWrapText(true);
    Font elementNameFont = this.workbook.createFont();
    elementNameFont.setBoldweight((short) 700);
    this.elementNameCellStyle.setFont(elementNameFont);

    this.elementNameCellStyle.setBorderBottom((short) 1);
    this.elementNameCellStyle.setBottomBorderColor(IndexedColors.WHITE.getIndex());
    this.elementNameCellStyle.setBorderLeft((short) 1);
    this.elementNameCellStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex());
    this.elementNameCellStyle.setBorderRight((short) 1);
    this.elementNameCellStyle.setRightBorderColor(IndexedColors.WHITE.getIndex());
    this.elementNameCellStyle.setBorderTop((short) 1);
    this.elementNameCellStyle.setTopBorderColor(IndexedColors.WHITE.getIndex());
}

From source file:edu.vt.vbi.patric.common.ExcelHelper.java

License:Apache License

/**
 * This method creates a map of Cellstyle objects for page building. Note: this method used for HSSF pages
 * /*from   w  ww.  j a  va 2 s. c o m*/
 * @return hashmap of styles
 */
private Map<String, CellStyle> createStyles() {

    // create custom colors
    HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette();

    // This replaces various shades of grey with custom colors
    palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, (byte) 0, // RGB red (0-255)
            (byte) 52, // RGB green
            (byte) 94 // RGB blue
    );
    palette.setColorAtIndex(HSSFColor.GREY_40_PERCENT.index, (byte) 230, (byte) 240, (byte) 248);
    palette.setColorAtIndex(HSSFColor.GREY_50_PERCENT.index, (byte) 255, (byte) 193, (byte) 193);

    // Create header style

    CellStyle style = createBorderStyle();

    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setColor(IndexedColors.WHITE.getIndex());

    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setWrapText(true);
    style.setFont(headerFont);
    styles.put("header", style);

    // Create alternating-color body styles

    Font bodyFont = wb.createFont();
    bodyFont.setFontHeightInPoints((short) 8);

    style = createBorderStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(bodyFont);
    style.setWrapText(true);
    styles.put("bg1", style);

    style = createBorderStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setWrapText(true);
    style.setFont(bodyFont);
    styles.put("bg2", style);

    // create style for empty cell
    style = createBorderStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(bodyFont);
    style.setWrapText(true);
    styles.put("empty", style);

    return styles;
}

From source file:edu.vt.vbi.patric.common.ExcelHelper.java

License:Apache License

/**
 * This method creates a map of Cellstyle objects for page building. Note: this method used for XSSF pages
 * //from  ww  w . j a  v  a 2 s. co m
 * @return hashmap of styles
 */
private Map<String, XSSFCellStyle> createXStyles() {

    XSSFCellStyle style = (XSSFCellStyle) createBorderStyle();

    // create style for cells in header row
    Font headerFont = xwb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setColor(IndexedColors.WHITE.getIndex());

    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(0, 52, 94)));
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setWrapText(true);
    style.setFont(headerFont);
    xstyles.put("header", style);

    // create styles for alternating background color cells
    Font bodyFont = xwb.createFont();
    bodyFont.setFontHeightInPoints((short) 8);

    style = (XSSFCellStyle) createBorderStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(230, 240, 248)));
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(bodyFont);
    style.setWrapText(true);
    xstyles.put("bg2", style);

    style = (XSSFCellStyle) createBorderStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setWrapText(true);
    style.setFont(bodyFont);
    xstyles.put("bg1", style);

    style = (XSSFCellStyle) createBorderStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 193, 193)));
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(bodyFont);
    style.setWrapText(true);
    xstyles.put("empty", style);

    return xstyles;
}

From source file:FormatStatics.HeaderFormats.java

private static short InterpretColor(String color) {
    switch (color) {
    case "blue":
        return IndexedColors.BLUE.getIndex();
    case "red":
        return IndexedColors.RED.getIndex();
    case "green":
        return IndexedColors.GREEN.getIndex();
    case "teal":
        return IndexedColors.TEAL.getIndex();
    case "orange":
        return IndexedColors.ORANGE.getIndex();
    default://from   ww  w.  j  av a 2  s .co m
        return IndexedColors.WHITE.getIndex();
    }
}

From source file:fr.amapj.service.engine.generator.excel.ExcelGeneratorTool.java

License:Open Source License

private void beWhite(CellStyle style) {
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFillForegroundColor(IndexedColors.WHITE.getIndex());

}

From source file:info.informationsea.tableio.excel.ExcelSheetWriter.java

License:Open Source License

public void registerBaseCellStyle(Object index, CellStyle style) {
    CellStyle baseCellStyles = style;//from   w w w  .j  a v  a2  s.co m

    // header style
    CellStyle headerCellStyles = sheet.getWorkbook().createCellStyle();
    headerCellStyles.cloneStyleFrom(style);
    Font headerFont = sheet.getWorkbook().createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerCellStyles.setFont(headerFont);
    headerCellStyles.setFillPattern(CellStyle.SOLID_FOREGROUND);
    headerCellStyles.setFillForegroundColor(IndexedColors.WHITE.getIndex());

    // alternative style
    CellStyle alternativeCellStyles = sheet.getWorkbook().createCellStyle();
    alternativeCellStyles.cloneStyleFrom(style);
    if (style instanceof XSSFCellStyle) {
        ((XSSFCellStyle) alternativeCellStyles).setFillForegroundColor(new XSSFColor(new Color(242, 242, 242)));
    } else {
        alternativeCellStyles.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    }
    alternativeCellStyles.setFillPattern(CellStyle.SOLID_FOREGROUND);

    // link style
    Font linkFont = sheet.getWorkbook().createFont();
    linkFont.setColor(IndexedColors.BLUE.getIndex());
    CellStyle linkStyle = sheet.getWorkbook().createCellStyle();
    linkStyle.cloneStyleFrom(baseCellStyles);
    linkStyle.setFont(linkFont);
    CellStyle alternativeLinkStyle = sheet.getWorkbook().createCellStyle();
    alternativeLinkStyle.cloneStyleFrom(alternativeCellStyles);
    alternativeLinkStyle.setFont(linkFont);

    Map<CellStyleType, CellStyle> styleMap = new HashMap<>();
    styleMap.put(CellStyleType.BASE, baseCellStyles);
    styleMap.put(CellStyleType.HEADER, headerCellStyles);
    styleMap.put(CellStyleType.ALTERNATIVE, alternativeCellStyles);
    styleMap.put(CellStyleType.BASE, baseCellStyles);
    styleMap.put(CellStyleType.LINK, linkStyle);
    styleMap.put(CellStyleType.LINK_ALTERNATIVE, alternativeLinkStyle);
    styles.put(index, styleMap);
}