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

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

Introduction

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

Prototype

IndexedColors GREEN

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

Click Source Link

Usage

From source file:com.github.luischavez.lat.excel.Excel.java

License:Open Source License

protected void setContent(Workbook workbook, Sheet sheet, String groupName) {
    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    style.setFont(font);//  w w  w. j a  v  a 2  s  .  c o m
    style.setFillBackgroundColor(IndexedColors.GREEN.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);

    Row row = sheet.createRow(0);
    this.createCell(0, row, style, "#");
    this.createCell(1, row, style, "Matricula");
    this.createCell(2, row, style, "Nombres");
    this.createCell(3, row, style, "Apellidos");
    for (int i = 0; i < 6; i++) {
        this.createCell(4 + i, row, style, "Practica #" + (i + 1));
    }
    this.createCell(10, row, style, "Promedio");

    int current = 1;
    RowList students = this.studentController.getByGroup(groupName);
    long groupId = this.groupController.getGroupId(groupName);
    for (com.github.luischavez.database.link.Row student : students) {
        long studentId = student.value("student_id", Long.class);
        String credential = student.value("credential", String.class);
        String firstName = student.value("first_name", String.class);
        String lastName = student.value("last_name", String.class);
        row = sheet.createRow(current);
        this.createNumber(0, row, null, current++);
        this.createCell(1, row, null, credential);
        this.createCell(2, row, null, firstName);
        this.createCell(3, row, null, lastName);
        for (int i = 0; i < 6; i++) {
            double qualification = this.qualificationController.get(groupId, studentId, i + 1);
            if (0 > qualification) {
                qualification = 0;
            }
            this.createNumber(4 + i, row, null, qualification);
        }
        this.createFormula(10, row, style, String.format("AVERAGE(E%d:J%d)", current, current));
    }
    row = sheet.createRow(current);
    this.createFormula(10, row, style, String.format("AVERAGE(K%d:K%d)", 2, current));
}

From source file:com.netxforge.netxstudio.server.logic.reporting.RFSServiceDashboardReportingLogic.java

License:Open Source License

/**
 * Write each Node per NodeType column, starting
 *///from  w  ww  .java 2  s  . co  m
@Override
protected void writeContent(Sheet sheet, Service service, Node node, int row, int column) {

    // Write the NODE.ID box.
    int newRow = NODE_ROW + (row * NODE_HEIGHT);
    int nodeColumn = NODE_COLUMN + (column * NODE_WIDTH);

    sheet.setColumnWidth(nodeColumn, 10 * 256);

    CellStyle nodeStyle = this.getWorkBook().createCellStyle();
    nodeStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    nodeStyle.setAlignment(CellStyle.ALIGN_CENTER);
    nodeStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    {
        Row cellRow = sheet.getRow(newRow);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellValue(node.getNodeID());
        c1.setCellStyle(nodeStyle);
    }
    {
        Row cellRow = sheet.getRow(newRow + 1);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 1);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellStyle(nodeStyle);
    }
    {
        Row cellRow = sheet.getRow(newRow + 2);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 2);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellStyle(nodeStyle);
    }

    sheet.addMergedRegion(new CellRangeAddress(newRow, newRow + NODE_HEIGHT - 2, nodeColumn, nodeColumn));

    // In between column.
    sheet.setColumnWidth(nodeColumn + 1, 2 * 256);

    // Write the RAG

    CellStyle ragStyle = this.getWorkBook().createCellStyle();

    ragStyle.setBorderTop(CellStyle.BORDER_THIN);
    ragStyle.setBorderBottom(CellStyle.BORDER_THIN);
    ragStyle.setBorderLeft(CellStyle.BORDER_THIN);
    ragStyle.setBorderRight(CellStyle.BORDER_THIN);
    ragStyle.setAlignment(CellStyle.ALIGN_CENTER);
    ragStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    ragStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    int ragColumn = nodeColumn + 2;
    sheet.setColumnWidth(ragColumn, 2 * 256);

    IMonitoringSummary summary = monStateModel.summary(new NullProgressMonitor(), node,
            new IComputationContext[] { new ObjectContext<Service>(service),
                    new ObjectContext<DateTimeRange>(getPeriod()) });
    if (summary == null) {
        return;
    }
    int[] rag = summary.rag();
    {
        Row cellRow = sheet.getRow(newRow);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow);
        }
        Cell c1 = cellRow.createCell(ragColumn);

        c1.setCellValue("R");

        CellStyle rStyle = this.getWorkBook().createCellStyle();
        rStyle.cloneStyleFrom(ragStyle);
        rStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
        c1.setCellStyle(rStyle);

        if (rag != null) {
            c1.setCellValue(rag[0]);
        }
    }
    {
        Row cellRow = sheet.getRow(newRow + 1);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 1);
        }
        Cell c1 = cellRow.createCell(ragColumn);

        c1.setCellValue("A");

        CellStyle aStyle = this.getWorkBook().createCellStyle();
        aStyle.cloneStyleFrom(ragStyle);
        aStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
        c1.setCellStyle(aStyle);

        if (rag != null) {
            c1.setCellValue(rag[1]);
        }
    }
    {
        Row cellRow = sheet.getRow(newRow + 2);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 2);
        }
        Cell c1 = cellRow.createCell(ragColumn);
        c1.setCellValue("G");
        CellStyle gStyle = this.getWorkBook().createCellStyle();
        gStyle.cloneStyleFrom(ragStyle);
        gStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
        c1.setCellStyle(gStyle);

        if (rag != null) {
            c1.setCellValue(rag[2]);
        }

    }
    // Clean our adapted summary.
    node.eAdapters().remove(summary);

}

From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java

public static ByteArrayOutputStream createTollUploadSuccessResponse() {
    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFFont font = wb.createFont();/*ww  w.  j av a 2 s.  c  o  m*/
    font.setColor(IndexedColors.GREEN.getIndex());
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFont(font);

    Sheet sheet = wb.createSheet();

    Row row = sheet.createRow(0);
    Cell cell = createExcelCell(sheet, row, 0, 256 * 100);
    cell.setCellStyle(cellStyle);
    cell.setCellValue("ALL tolls uploaded successfully");

    return createOutputStream(wb);
}

From source file:com.saba.CalendarDemo.java

License:Apache License

private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style;/*from  ww  w  .j a  v a  2 s .c  o m*/
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Trebuchet MS");
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.GREEN.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styles.put("title", style);

    Font itemFontLeft = wb.createFont();
    itemFontLeft.setFontHeightInPoints((short) 11);
    itemFontLeft.setFontName("Trebuchet MS");
    itemFontLeft.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setFont(itemFontLeft);
    styles.put("item_left", style);

    Font itemFontRight = wb.createFont();
    itemFontRight.setFontHeightInPoints((short) 10);
    itemFontRight.setFontName("Trebuchet MS");
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setFont(itemFontRight);
    styles.put("item_right", style);

    return styles;
}

From source file:com.wantdo.stat.excel.poi_src.ConditionalFormats.java

License:Apache License

/**
 * Highlight cells based on their values
 */// ww  w.  j a v  a 2  s.  co m
static void sameCell(Sheet sheet) {
    sheet.createRow(0).createCell(0).setCellValue(84);
    sheet.createRow(1).createCell(0).setCellValue(74);
    sheet.createRow(2).createCell(0).setCellValue(50);
    sheet.createRow(3).createCell(0).setCellValue(51);
    sheet.createRow(4).createCell(0).setCellValue(49);
    sheet.createRow(5).createCell(0).setCellValue(41);

    SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();

    // Condition 1: Cell Value Is   greater than  70   (Blue Fill)
    ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.GT, "70");
    PatternFormatting fill1 = rule1.createPatternFormatting();
    fill1.setFillBackgroundColor(IndexedColors.BLUE.index);
    fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

    // Condition 2: Cell Value Is  less than      50   (Green Fill)
    ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.LT, "50");
    PatternFormatting fill2 = rule2.createPatternFormatting();
    fill2.setFillBackgroundColor(IndexedColors.GREEN.index);
    fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

    CellRangeAddress[] regions = { CellRangeAddress.valueOf("A1:A6") };

    sheetCF.addConditionalFormatting(regions, rule1, rule2);

    sheet.getRow(0).createCell(2).setCellValue("<== Condition 1: Cell Value Is greater than 70 (Blue Fill)");
    sheet.getRow(4).createCell(2).setCellValue("<== Condition 2: Cell Value Is less than 50 (Green Fill)");
}

From source file:eventHandlers.CompareDrotVSRoster.java

private void foregroundColorSetUp(Row row, XSSFWorkbook myWorkBook) {
    Cell ssnCell = row.getCell(GlobalVar.LAST4_CELL_INDEX_V1);
    DataFormatter df = new DataFormatter();
    String ssnString = df.formatCellValue(ssnCell); //return ***-**-****
    ssnString = ssnString.replace("-", "");

    Cell soCell = row.getCell(GlobalVar.SIGN_OUT_DATE_CELL_INDEX_V1);
    String signOutDateString = df.formatCellValue(soCell); //return ***-**-****

    Cell ctrlNumCell = row.getCell(GlobalVar.CTRL_NUM_CELL_INDEX_V1);
    String ctrlNumString = ctrlNumCell.getStringCellValue();
    if (proclibrary.containsKey(ssnString)) { // Map< SSN, Map<ctrlNum, signOutdate>>
        Map<String, String> leaves = proclibrary.get(ssnString);
        if (leaves.containsKey(ctrlNumString)) {
            String date = leaves.get(ctrlNumString);
            if (date.equals(signOutDateString)) {
                CellStyle style = createStandardStyle(myWorkBook);
                style.setFillForegroundColor(IndexedColors.GREEN.getIndex());
                style.setFillPattern(CellStyle.SOLID_FOREGROUND);
                ctrlNumCell.setCellStyle(style);
            }//  ww w  .j a  va2 s.  c o  m
        }
    } else if (rejlibrary.containsKey(ssnString)) {
        Map<String, String> leaves = rejlibrary.get(ssnString);
        if (leaves.containsKey(ctrlNumString)) {
            String date = leaves.get(ctrlNumString);
            if (date.equals(signOutDateString)) {
                CellStyle style = createStandardStyle(myWorkBook);
                style.setFillForegroundColor(IndexedColors.RED.getIndex());
                style.setFillPattern(CellStyle.SOLID_FOREGROUND);
                ctrlNumCell.setCellStyle(style);
            }
        }
    } else if (recylibrary.containsKey(ssnString)) {
        Map<String, String> leaves = recylibrary.get(ssnString);
        if (leaves.containsKey(ctrlNumString)) {
            String date = leaves.get(ctrlNumString);
            if (date.equals(signOutDateString)) {
                CellStyle style = createStandardStyle(myWorkBook);
                style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
                style.setFillPattern(CellStyle.SOLID_FOREGROUND);
                ctrlNumCell.setCellStyle(style);
            }
        }
    }
}

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 w  w w .j a v  a 2  s .co  m
        return IndexedColors.WHITE.getIndex();
    }
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

protected short colorToIndex(Workbook wb, Color color) {
    if (color == null) {
        return 0;
    }/*ww w. j a va  2 s  .  c o m*/
    if (Color.black.equals(color)) {
        return IndexedColors.BLACK.getIndex();
    }
    if (Color.white.equals(color)) {
        return IndexedColors.WHITE.getIndex();
    }
    if (Color.blue.equals(color) || Color.blue.darker().equals(color) || Color.blue.brighter().equals(color)) {
        return IndexedColors.BLUE.getIndex();
    }
    if (Color.red.equals(color) || Color.red.darker().equals(color) || Color.red.brighter().equals(color)) {
        return IndexedColors.RED.getIndex();
    }
    if (Color.LIGHT_GRAY.equals(color)) {
        return IndexedColors.GREY_25_PERCENT.getIndex();
    }
    if (Color.GRAY.equals(color)) {
        return IndexedColors.GREY_50_PERCENT.getIndex();
    }
    if (Color.DARK_GRAY.equals(color)) {
        return IndexedColors.GREY_80_PERCENT.getIndex();
    }
    if (Color.green.equals(color) || Color.green.brighter().equals(color)
            || Color.green.darker().equals(color)) {
        return IndexedColors.GREEN.getIndex();
    }
    if (Color.magenta.equals(color) || Color.magenta.darker().equals(color)
            || Color.magenta.brighter().equals(color)) {
        return IndexedColors.MAROON.getIndex();
    }
    if (Color.orange.equals(color) || Color.orange.darker().equals(color)
            || Color.orange.brighter().equals(color)) {
        return IndexedColors.ORANGE.getIndex();
    }
    if (Color.pink.equals(color) || Color.pink.darker().equals(color) || Color.pink.brighter().equals(color)) {
        return IndexedColors.PINK.getIndex();
    }
    if (Color.yellow.equals(color) || Color.yellow.darker().equals(color)
            || Color.yellow.brighter().equals(color)) {
        return IndexedColors.YELLOW.getIndex();
    }

    byte r = (byte) color.getRed();
    byte g = (byte) color.getGreen();
    byte b = (byte) color.getBlue();
    HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette();
    HSSFColor hssColor = palette.findColor(r, g, b);

    try {
        if (hssColor == null) {
            hssColor = palette.addColor(r, g, b);
        }
        return hssColor.getIndex();
    } catch (RuntimeException e) {
        hssColor = palette.findSimilarColor(r, g, b);
        return hssColor != null ? hssColor.getIndex() : 0;
    }
}

From source file:jdbreport.model.io.xls.poi.Excel2007Writer.java

License:Apache License

protected short colorToIndex(Workbook wb, Color color) {
    if (color == null) {
        return 0;
    }//from w  ww  .j  av  a 2s . c o  m
    if (Color.black.equals(color)) {
        return IndexedColors.BLACK.getIndex();
    }
    if (Color.white.equals(color)) {
        return IndexedColors.WHITE.getIndex();
    }
    if (Color.blue.equals(color) || Color.blue.darker().equals(color) || Color.blue.brighter().equals(color)) {
        return IndexedColors.BLUE.getIndex();
    }
    if (Color.red.equals(color) || Color.red.darker().equals(color) || Color.red.brighter().equals(color)) {
        return IndexedColors.RED.getIndex();
    }
    if (Color.LIGHT_GRAY.equals(color)) {
        return IndexedColors.GREY_25_PERCENT.getIndex();
    }
    if (Color.GRAY.equals(color)) {
        return IndexedColors.GREY_50_PERCENT.getIndex();
    }
    if (Color.DARK_GRAY.equals(color)) {
        return IndexedColors.GREY_80_PERCENT.getIndex();
    }
    if (Color.green.equals(color) || Color.green.brighter().equals(color)
            || Color.green.darker().equals(color)) {
        return IndexedColors.GREEN.getIndex();
    }
    if (Color.magenta.equals(color) || Color.magenta.darker().equals(color)
            || Color.magenta.brighter().equals(color)) {
        return IndexedColors.MAROON.getIndex();
    }
    if (Color.orange.equals(color) || Color.orange.darker().equals(color)
            || Color.orange.brighter().equals(color)) {
        return IndexedColors.ORANGE.getIndex();
    }
    if (Color.pink.equals(color) || Color.pink.darker().equals(color) || Color.pink.brighter().equals(color)) {
        return IndexedColors.PINK.getIndex();
    }
    if (Color.yellow.equals(color) || Color.yellow.darker().equals(color)
            || Color.yellow.brighter().equals(color)) {
        return IndexedColors.YELLOW.getIndex();
    }

    XSSFColor xssfColor = new XSSFColor(color);
    return xssfColor.getIndexed();
}

From source file:jp.ac.utokyo.rcast.karkinos.summary.SummaryStats.java

License:Apache License

private static CellStyle getCS(XSSFWorkbook wb, int i) {
    CellStyle cs = wb.createCellStyle();
    cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
    if (i == 1) {
        ////from w  w w.  j av  a2 s.  c  o m
        cs.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());

    } else if (i == 2) {
        //
        cs.setFillForegroundColor(IndexedColors.GREEN.getIndex());

    } else {
        cs.setFillForegroundColor(IndexedColors.PINK.getIndex());
    }
    return cs;
}