Example usage for org.apache.poi.ss.usermodel CellStyle setFillPattern

List of usage examples for org.apache.poi.ss.usermodel CellStyle setFillPattern

Introduction

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

Prototype

void setFillPattern(FillPatternType fp);

Source Link

Document

setting to one fills the cell with the foreground color...

Usage

From source file:Utilities.BatchInDJMSHelper.java

private void colorInvalidLeave(String msg, XSSFWorkbook myWorkBook, Cell ctrlNumCell) {
    int errCode = Integer.parseInt(msg.substring(msg.length() - 1));
    System.out.println("BatchInDJMS.java: error code is " + errCode);
    CellStyle style = GlobalVar.createStandardStyle(myWorkBook);

    style.setFillForegroundColor(colorErrorMap(errCode)); //color map conversion
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    // cellStyle = ctrlNumCell.
    ctrlNumCell.setCellStyle(style);//from w ww  . j  a  v a2 s  .  c o  m
}

From source file:Utilities.BatchInDJMSHelper.java

private void legendBuilder(XSSFWorkbook myWorkBook) {
    XSSFSheet mySheet = myWorkBook.getSheetAt(0);
    Row row1;/* w  w w .  ja va2  s.  c o m*/
    Row row2;
    Row row3;
    Row row4;
    System.out.println("BatchInDJMSHelper.java: Line number in xlsx" + mySheet.getPhysicalNumberOfRows());
    // Create a row and put some cells in it.
    if (mySheet.getPhysicalNumberOfRows() > GlobalVar.LEGEND_Y) {
        row1 = mySheet.getRow(GlobalVar.LEGEND_Y);
    } else {
        row1 = mySheet.createRow(GlobalVar.LEGEND_Y);
    }

    if (mySheet.getPhysicalNumberOfRows() > GlobalVar.LEGEND_Y + 1) {
        row2 = mySheet.getRow(GlobalVar.LEGEND_Y + 1);
    } else {
        row2 = mySheet.createRow(GlobalVar.LEGEND_Y + 1);
    }

    if (mySheet.getPhysicalNumberOfRows() > GlobalVar.LEGEND_Y + 2) {
        row3 = mySheet.getRow(GlobalVar.LEGEND_Y + 2);
    } else {
        row3 = mySheet.createRow(GlobalVar.LEGEND_Y + 2);
    }

    if (mySheet.getPhysicalNumberOfRows() > GlobalVar.LEGEND_Y + 3) {
        row4 = mySheet.getRow(GlobalVar.LEGEND_Y + 3);
    } else {
        row4 = mySheet.createRow(GlobalVar.LEGEND_Y + 3);
    }
    // Row row2 = mySheet.getRow(GlobalVar.LEGEND_Y + 1);
    //        Row row3 = mySheet.getRow(GlobalVar.LEGEND_Y + 2);
    //        Row row4 = mySheet.getRow(GlobalVar.LEGEND_Y + 3);

    int col1 = GlobalVar.LEGEND_X;
    int col2 = GlobalVar.LEGEND_X + 1;
    int col3 = GlobalVar.LEGEND_X + 2;
    int col4 = GlobalVar.LEGEND_X + 3;

    //// row 1
    CellStyle style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.ETS_STATUS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    Cell cell = row1.createCell(col1);
    cell.setCellValue("ETS");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.BAD_STATUS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row1.createCell(col2);
    cell.setCellValue("Bad");
    cell.setCellStyle(style);
    style = myWorkBook.createCellStyle();

    style.setFillForegroundColor(GlobalVar.OVERLAP_LV_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row1.createCell(col3);
    cell.setCellValue("Overlap Lv");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.DUPLICATE_LV_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row1.createCell(col4);
    cell.setCellValue("Duplicate Lv");
    cell.setCellStyle(style);

    //            case INPROCESSING_ERR: return INPROCESSING_COLOR;
    //            case AFTER_PCS_ERR: return AFTER_PCS_COLOR;     
    //// row 2
    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.WRONG_SSN_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col1);
    cell.setCellValue("Wrong SSN");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.DUPLICATE_CTRL_NUM_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col2);
    cell.setCellValue("Duplicate CtrlNum");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.INPROCESSING_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col3);
    cell.setCellValue("Inprocessing");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.AFTER_PCS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col4);
    cell.setCellValue("After PCS");
    cell.setCellStyle(style);

    // row3
    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.IN_CYCLE_DUPLICATE_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row3.createCell(col1);
    cell.setCellValue("In-cycle duplicates/Invalid first five");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(GlobalVar.AUDITOR_DELETED_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row3.createCell(col2);
    cell.setCellValue("Auditor deleted");
    cell.setCellStyle(style);

}

From source file:utilities.DebtMgmtBatchInDJMS.java

private void colorTransactions(String ssn, Cell ssnCell, XSSFWorkbook myWorkBook) {
    // color valid leaves        
    if (SSN_MAP.containsKey(ssn)) { // Map< SSN, Map<ctrlNum, signOutdate>>        
        CellStyle style = createStandardStyle(myWorkBook);
        int msgCode = SSN_MAP.get(ssn);
        System.out.println("MSG Code: " + msgCode);
        style.setFillForegroundColor(colorMsgMap(msgCode));
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        ssnCell.setCellStyle(style);/*from www .j a v a  2s.co  m*/
    }
}

From source file:utilities.DebtMgmtBatchInDJMS.java

private void legendBuilder(XSSFWorkbook myWorkBook) {
    XSSFSheet mySheet = myWorkBook.getSheetAt(0);
    // Create a row and put some cells in it.
    Row row1 = mySheet.getRow(LEGEND_Y);
    Row row2 = mySheet.getRow(LEGEND_Y + 1);
    Row row3 = mySheet.getRow(LEGEND_Y + 2);
    Row row4 = mySheet.getRow(LEGEND_Y + 3);

    int col1 = LEGEND_X;
    int col2 = LEGEND_X + 1;
    int col3 = LEGEND_X + 2;
    int col4 = LEGEND_X + 3;

    //// row 1/*from w  ww  . j a  v a  2  s  . co m*/
    CellStyle style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(ETS_STATUS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    Cell cell = row1.createCell(col1);
    cell.setCellValue("ETS");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(BAD_STATUS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row1.createCell(col2);
    cell.setCellValue("Bad");
    cell.setCellStyle(style);
    style = myWorkBook.createCellStyle();

    style.setFillForegroundColor(SUSPENDED_STATUS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row1.createCell(col3);
    cell.setCellValue("Suspended");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(PRA_STATUS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row1.createCell(col4);
    cell.setCellValue("PRA");
    cell.setCellStyle(style);

    //// row 2
    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(FULLY_COLLRECTED_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col1);
    cell.setCellValue("Fully Collected");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(WOUNDED_WARRIOR_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col2);
    cell.setCellValue("WW");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(NEW_ENT_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col3);
    cell.setCellValue("New Entitlement");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(DEBT_LETTER_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row2.createCell(col4);
    cell.setCellValue("Debt Letter");
    cell.setCellStyle(style);

    //// row 3
    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(COLLECTING_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row3.createCell(col1);
    cell.setCellValue("Collecting");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(PCS_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row3.createCell(col2);
    cell.setCellValue("PCS");
    cell.setCellStyle(style);

    style = myWorkBook.createCellStyle();
    style.setFillForegroundColor(QUESTIONABLE_COLOR);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell = row3.createCell(col3);
    cell.setCellValue("Questionable");
    cell.setCellStyle(style);
}

From source file:Utilities.ExportToXLSX.java

private void createHeaderRow(Boolean isNewLeave, String fileName) throws IOException {
    // WB = new XSSFWorkbook(); 
    FileOutputStream output;/*from w  w  w.j  av  a 2 s .  co m*/
    //Sheet sheet;

    int titleLen;
    String[] header; // the header of the spreadsheet
    if (isNewLeave) {
        //            titleLen = GlobalVar.NEW_LEAVE_TITLES.length; 
        //            sheet = wb.createSheet("New Leave Form");          
        //            header = GlobalVar.NEW_LEAVE_TITLES;
        titleLen = GlobalVar.LEAVE_TITLES_V1.length;
        sheet = wb.createSheet("New Leave Form");
        header = GlobalVar.LEAVE_TITLES_V1;
    } else {
        //            titleLen = GlobalVar.SIGNED_LEAVE_TITLES.length; 
        //            sheet = wb.createSheet("SIGNED Leave Form");
        //            header = GlobalVar.SIGNED_LEAVE_TITLES;
        titleLen = GlobalVar.LEAVE_TITLES_V1.length;
        sheet = wb.createSheet("SIGNED Leave Form");
        header = GlobalVar.LEAVE_TITLES_V1;
    }

    //set column widths, the width is measured in units of 1/256th of a character width
    for (int i = 0; i < titleLen; i++) {
        sheet.setColumnWidth(i, 256 * GlobalVar.COL_WIDTH);
    }

    // create style for the first row
    CellStyle style;
    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createStandardStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);

    Row row = sheet.createRow(0); // first row

    //set value for the first row
    for (int i = 0; i < header.length; i++) {
        Cell cell = row.createCell(i);
        cell.setCellValue(header[i]);
        cell.setCellStyle(style);
    }

    //freeze the first row
    sheet.createFreezePane(0, 1);

    try {
        output = new FileOutputStream(fileName);
        wb.write(output);
        output.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ExportToXLSX.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, "Failed: Excel worksheet is used by another user!");
    }

}

From source file:utilities.XlsxGenerator.java

private CellStyle createRCFStyle() {
    CellStyle style = createStandardStyle();
    style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    return style;
}

From source file:utilities.XlsxGenerator.java

private CellStyle createDMPOStyle() {
    CellStyle style = createStandardStyle();
    style.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    return style;
}

From source file:vistas.reportes.procesos.rptVacacionesExcel.java

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();/*from w w w. j a  va 2  s. c om*/
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font monthFont = wb.createFont();
    monthFont.setFontHeightInPoints((short) 11);
    monthFont.setColor(IndexedColors.WHITE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(monthFont);
    style.setWrapText(true);
    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

    return styles;
}