Example usage for org.apache.poi.xssf.usermodel XSSFCellStyle setFont

List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setFont

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFCellStyle setFont.

Prototype

@Override
public void setFont(Font font) 

Source Link

Document

Set the font for this style

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  a2  s.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() + " ");
            }// w  w w  . j  a v a2  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.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  w  w  w . j  ava 2 s. c om*/
 * @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:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-3]  ? ?  :  ?? ?(? ?, Border? ?, ? ?,  )? 
 *///from ww  w.  j  a  va 2 s .c  o  m
@Test
public void testWriteExcelFileAttribute() throws Exception {

    try {
        LOGGER.debug("testWriteExcelFileAttribute start....");

        short rowheight = 40 * 10;
        int columnwidth = 30;

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testWriteExcelFileAttribute.xlsx");

        // delete file
        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            LOGGER.debug("Delete file....{}", sb.toString());
        }

        XSSFWorkbook wb = new XSSFWorkbook();

        XSSFSheet sheet1 = wb.createSheet("new sheet");
        wb.createSheet("second sheet");

        // ? ?
        sheet1.setDefaultRowHeight(rowheight);
        sheet1.setDefaultColumnWidth(columnwidth);

        Font f2 = wb.createFont();
        XSSFCellStyle cs = wb.createCellStyle();

        cs.setFont(f2);
        cs.setWrapText(true);

        // 
        cs.setAlignment(CellStyle.ALIGN_RIGHT);
        cs.setFillPattern(CellStyle.DIAMONDS); //  ?

        XSSFRow r1 = sheet1.createRow(0);
        r1.createCell(0);

        // ? ?
        cs.setFillForegroundColor(IndexedColors.BLUE.getIndex()); //  
        cs.setFillBackgroundColor(IndexedColors.RED.getIndex()); // 

        sheet1.setDefaultColumnStyle((short) 0, cs);

        Workbook tmp = excelService.createWorkbook(wb, sb.toString());

        Sheet sheetTmp1 = tmp.getSheetAt(0);

        assertEquals(rowheight, sheetTmp1.getDefaultRowHeight());
        assertEquals(columnwidth, sheetTmp1.getDefaultColumnWidth());

        CellStyle cs1 = tmp.getCellStyleAt((short) (tmp.getNumCellStyles() - 1));

        LOGGER.debug("getAlignment : {}", cs1.getAlignment());
        assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment());

        LOGGER.debug("getFillPattern : {}", cs1.getFillPattern());
        assertEquals(XSSFCellStyle.DIAMONDS, cs1.getFillPattern());

        LOGGER.debug("getFillForegroundColor : {}", cs1.getFillForegroundColor());
        LOGGER.debug("getFillBackgroundColor : {}", cs1.getFillBackgroundColor());

        LOGGER.debug(
                "XSSFWorkbook.getFillBackgroundColor(), XSSFColor().getIndexed() ? ? 0 ? ?");

        assertEquals(IndexedColors.BLUE.getIndex(), cs1.getFillForegroundColor());
        assertEquals(IndexedColors.RED.getIndex(), cs1.getFillBackgroundColor());

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testWriteExcelFileAttribute end....");
    }
}

From source file:es.tena.foundation.util.POIUtil.java

/**
 * Crea un map con los estilos para cada tipo de datos
 *
 * @param wb/*from   w  w  w  .j a  v a 2 s . c om*/
 * @return un hashMap con las claves 'porcentaje', 'coeficiente', 'moneda',
 * 'fecha' y 'cabecera'
 */
public static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb) {
    Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
    XSSFDataFormat fmt = wb.createDataFormat();

    XSSFCellStyle style1 = wb.createCellStyle();
    style1.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
    style1.setDataFormat(fmt.getFormat("0.0%"));
    styles.put("porcentaje", style1);

    XSSFCellStyle style2 = wb.createCellStyle();
    style2.setAlignment(XSSFCellStyle.ALIGN_CENTER);
    style2.setDataFormat(fmt.getFormat("0.0X"));
    styles.put("coeficiente", style2);

    XSSFCellStyle style3 = wb.createCellStyle();
    style3.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
    style3.setDataFormat(fmt.getFormat("#,##0.00"));
    styles.put("moneda", style3);

    XSSFCellStyle style4 = wb.createCellStyle();
    style4.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
    style4.setDataFormat(fmt.getFormat("mmm dd"));
    styles.put("fecha", style4);

    XSSFCellStyle style5 = wb.createCellStyle();
    XSSFFont headerFont = wb.createFont();
    headerFont.setBold(true);
    style5.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style5.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    style5.setFont(headerFont);
    styles.put("cabecera", style5);

    return styles;
}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixEngine.java

License:Open Source License

/**
 * Creates the row header.//from  w  w w  . ja  va  2  s .c om
 *
 * @param workbook the workbook
 * @param sheet the sheet
 * @param rowIndex the row index
 * @param label1 the label1
 * @param label2 the label2
 */
public void createRowHeader(XSSFWorkbook workbook, XSSFSheet sheet, int rowIndex, String label1,
        String label2) {

    // Create the needed highlight style.
    XSSFCellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(197, 217, 241)));
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    XSSFFont font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);

    // Create the requested row.
    XSSFRow row = sheet.createRow(0);
    XSSFCell cell = row.createCell(0);
    cell.setCellValue(label1);
    cell.setCellStyle(cellStyle);
    cell = row.createCell(1);
    cell.setCellValue(label2);
    cell.setCellStyle(cellStyle);

}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java

License:Open Source License

/**
 * Write./* ww  w . j  a  v  a  2s.c  o  m*/
 *
 * @param fileName            the file name
 * @return true, if successful
 */
public boolean write(String fileName) {

    // Check for errors.
    try {

        // Create the requested workbook image.
        XSSFWorkbook workbook = new XSSFWorkbook();

        // Create the needed highlight style.
        XSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        cellStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(197, 217, 241)));
        cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        XSSFFont font = workbook.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);

        // Fill in the fitness sheet.
        this.writeFitnessFunctionInformation(workbook, cellStyle);

        // Fill in the variables.
        this.writeScanVariables(workbook, cellStyle);

        // Attempt to create the requested file from the workbook image.
        FileOutputStream file = new FileOutputStream(fileName);
        workbook.write(file);
        file.close();

        // Catch errors.
    } catch (Exception e) {

        // Note the error.
        return false;

    }

    // Return the default results.
    return true;

}

From source file:gov.nih.nci.evs.app.neopl.CSVtoExcel.java

License:Open Source License

public void runXSSF(String inputfile) {
    int size = checkSpecialCharacters(inputfile);

    int n = inputfile.lastIndexOf(".");
    //String outputfile = inputfile.substring(0, n) + ".xlsx";
    String outputfile = getOutputFile(inputfile, ".xlsx");

    try {/* w w w .j a  v a2s  .com*/
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFCreationHelper helper = null;

        XSSFCellStyle cellStyle = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);

        XSSFCellStyle linkCellStyle = wb.createCellStyle();
        XSSFFont linkfont = wb.createFont();

        //XSSFColor color = new XSSFColor(Color.LIGHT_BLUE);
        XSSFColor color = new XSSFColor(Color.BLUE);
        linkfont.setColor(color);

        //linkfont.setColor(XSSFColor.LIGHT_BLUE.index);
        linkCellStyle.setFont(linkfont);
        CSVReader reader = new CSVReader(new FileReader(inputfile));//CSV file
        String[] line;
        int r = 0;
        Cell cell = null;

        XSSFHyperlink url_link = null;
        XSSFSheet sheet = null;

        int page_num = 1;
        Row row = null;
        int lcv = 0;
        int row_count = 0;

        try {

            while ((line = reader.readNext()) != null) {
                if (lcv % PAGE_SIZE == 0) {
                    r = 0;
                    String sheetLabel = SHEET_LABEL;
                    if (size > PAGE_SIZE) {
                        sheetLabel = sheetLabel + " (Page " + page_num + ")";
                    }
                    //System.out.println("Creating " + sheetLabel);
                    sheet = wb.createSheet(sheetLabel);
                    helper = sheet.getWorkbook().getCreationHelper();
                    url_link = helper.createHyperlink(XSSFHyperlink.LINK_URL);

                    row = sheet.createRow((short) r);
                    for (int i = 0; i < HEADINGS.length; i++) {
                        String heading = HEADINGS[i];
                        cell = row.createCell(i);
                        cell.setCellValue(heading);
                        cell.setCellStyle(cellStyle);
                    }
                    page_num++;

                } else {
                    String s4 = (String) line[4];
                    s4 = s4.trim();
                    r++;
                    row = sheet.createRow((short) r);
                    row_count++;
                    cell = row.createCell(0);
                    String ncit_code = line[0];
                    cell.setCellValue(ncit_code);
                    if (NCIT_LINK) {
                        url_link = helper.createHyperlink(XSSFHyperlink.LINK_URL);
                        url_link.setAddress(getNCItHyperlink(ncit_code));
                        cell.setHyperlink(url_link);
                        cell.setCellStyle(linkCellStyle);
                    }

                    cell = row.createCell(1);
                    String name = line[1];
                    cell.setCellValue(line[1]);

                    cell = row.createCell(2);
                    cell.setCellValue(line[2]);
                    if (NCIM_LINK) {
                        String s2 = line[2];
                        s2 = s2.trim();
                        if (s2.length() > 0) {
                            url_link = helper.createHyperlink(XSSFHyperlink.LINK_URL);
                            url_link.setAddress(getNCImHyperlink(s2));
                            cell.setHyperlink(url_link);
                            cell.setCellStyle(linkCellStyle);
                        }
                    }

                    cell = row.createCell(3);
                    String ncim_name = line[3];
                    cell.setCellValue(line[3]);

                    cell = row.createCell(4);
                    cell.setCellValue(line[4]);

                    cell = row.createCell(5);
                    String atom_name = (String) line[5];
                    cell.setCellValue(line[5]);

                    cell = row.createCell(6);
                    cell.setCellValue(line[6]);

                    if (SOURCE_LINK) {
                        if (s4.length() > 0) {
                            String s6 = (String) line[6];
                            if (localNameMap.containsKey(s4)) {
                                url_link = helper.createHyperlink(XSSFHyperlink.LINK_URL);
                                s4 = (String) localNameMap.get(s4);
                                url_link.setAddress(getSourceHyperlink(s4, s6));
                                cell.setHyperlink(url_link);
                                cell.setCellStyle(linkCellStyle);
                            }
                        }
                    }
                    cell = row.createCell(7);
                    cell.setCellValue(line[7]);
                }
                lcv++;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream(outputfile);
        wb.write(fileOut);
        fileOut.close();
        System.out.println("Output file " + outputfile + " generated.");
        System.out.println("row_count: " + row_count);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:htmlparser.xls.XLSFile.java

public void createScoreTable(XSSFColor oddrow_color, XSSFColor title_bg_color, XSSFColor title_font_color,
        int highlight) {

    String sheetname = WorkbookUtil.createSafeSheetName(this.parser.getCompetitionName());
    this.scoresheet = this.excelfile.createSheet(sheetname);

    CreationHelper createHelper = this.excelfile.getCreationHelper();

    CellStyle cellStyle = this.excelfile.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

    int rows = 0;

    Row headline = this.scoresheet.createRow(rows);
    Cell cheadline = headline.createCell(0);
    cheadline.setCellValue(createHelper.createRichTextString(this.parser.getCompetitionName()));
    XSSFCellStyle customstyle = (XSSFCellStyle) this.excelfile.createCellStyle();
    customstyle.cloneStyleFrom(cellStyle);
    XSSFFont fh = (XSSFFont) this.excelfile.createFont();
    fh.setFontHeightInPoints((short) 16);
    fh.setBoldweight(Font.BOLDWEIGHT_BOLD);
    fh.setColor(title_bg_color);//  w  ww  .  j a v  a 2s .  co  m
    customstyle.setFont(fh);
    cheadline.setCellStyle(customstyle);
    int length = this.parser.getTeams().get(0).getData().size();
    CellRangeAddress headrow = new CellRangeAddress(rows, rows, 0, length);
    this.scoresheet.addMergedRegion(headrow);
    RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, headrow, this.scoresheet, this.excelfile);
    RegionUtil.setBottomBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.scoresheet, this.excelfile);
    RegionUtil.setBorderLeft(CellStyle.BORDER_THIN, headrow, this.scoresheet, this.excelfile);
    RegionUtil.setLeftBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.scoresheet, this.excelfile);
    RegionUtil.setBorderRight(CellStyle.BORDER_THIN, headrow, this.scoresheet, this.excelfile);
    RegionUtil.setRightBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.scoresheet, this.excelfile);
    RegionUtil.setBorderTop(CellStyle.BORDER_THIN, headrow, this.scoresheet, this.excelfile);
    RegionUtil.setTopBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.scoresheet, this.excelfile);
    rows++;

    Row colNms = this.scoresheet.createRow(rows++);
    customstyle = (XSSFCellStyle) this.excelfile.createCellStyle();
    customstyle.cloneStyleFrom(cellStyle);
    customstyle.setFillForegroundColor(title_bg_color);
    customstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    XSSFFont f1 = (XSSFFont) this.excelfile.createFont();
    f1.setColor(title_font_color);
    f1.setBoldweight(Font.BOLDWEIGHT_BOLD);
    customstyle.setFont(f1);
    int cCN = 0;
    for (String s : this.shColNms) {

        Cell c = colNms.createCell(cCN);
        c.setCellValue(createHelper.createRichTextString(s));
        c.setCellStyle(customstyle);
        cCN++;

    }

    double ordNum = 1;

    customstyle = (XSSFCellStyle) this.excelfile.createCellStyle();
    customstyle.cloneStyleFrom(cellStyle);
    customstyle.setFillForegroundColor(oddrow_color);
    customstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    for (Team t : this.parser.getTeams()) {

        Row r = this.scoresheet.createRow(rows++);

        int cell = 0;

        Cell order = r.createCell(cell++);
        order.setCellValue(ordNum++);
        if (rows % 2 == 0)
            order.setCellStyle(customstyle);
        else
            order.setCellStyle(cellStyle);

        for (String s : t.getData()) {

            Cell c = r.createCell(cell);

            c.setCellValue(createHelper.createRichTextString(s));

            if (rows % 2 == 0)
                c.setCellStyle(customstyle);
            else
                c.setCellStyle(cellStyle);

            cell++;

        }

    }

    for (int i = 0; i <= length; i++) {

        this.scoresheet.autoSizeColumn(i);

    }

    if (highlight >= 0) {

        highlight += 2;

        Row r = this.scoresheet.getRow(highlight);
        customstyle = (XSSFCellStyle) this.excelfile.createCellStyle();
        customstyle.cloneStyleFrom(r.getCell(0).getCellStyle());
        Font bold = this.excelfile.createFont();
        bold.setBoldweight(Font.BOLDWEIGHT_BOLD);
        customstyle.setFont(bold);

        for (Cell c : r) {
            c.setCellStyle(customstyle);
        }
    }

}

From source file:htmlparser.xls.XLSFile.java

public void createMatchTable(XSSFColor oddrow_color, XSSFColor title_bg_color, XSSFColor title_font_color) {

    String sheetname = WorkbookUtil.createSafeSheetName(this.parser.getTeamName());
    this.matchsheet = this.excelfile.createSheet(sheetname);

    CreationHelper createHelper = this.excelfile.getCreationHelper();

    CellStyle cellStyle = this.excelfile.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

    int rows = 0;

    Row headline = this.matchsheet.createRow(rows);
    Cell cheadline = headline.createCell(0);
    cheadline.setCellValue(createHelper.createRichTextString(this.parser.getTeamName()));
    XSSFCellStyle customstyle = (XSSFCellStyle) this.excelfile.createCellStyle();
    customstyle.cloneStyleFrom(cellStyle);
    XSSFFont fh = (XSSFFont) this.excelfile.createFont();
    fh.setFontHeightInPoints((short) 16);
    fh.setBoldweight(Font.BOLDWEIGHT_BOLD);
    fh.setColor(title_bg_color);/*www  .  j  av a 2 s .  c o  m*/
    customstyle.setFont(fh);
    cheadline.setCellStyle(customstyle);
    int length = this.parser.getMatches().get(0).getData().size();
    CellRangeAddress headrow = new CellRangeAddress(rows, rows, 0, length - 1);
    this.matchsheet.addMergedRegion(headrow);
    RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile);
    RegionUtil.setBottomBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile);
    RegionUtil.setBorderLeft(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile);
    RegionUtil.setLeftBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile);
    RegionUtil.setBorderRight(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile);
    RegionUtil.setRightBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile);
    RegionUtil.setBorderTop(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile);
    RegionUtil.setTopBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile);
    rows++;

    Row colNms = this.matchsheet.createRow(rows++);
    customstyle = (XSSFCellStyle) this.excelfile.createCellStyle();
    customstyle.cloneStyleFrom(cellStyle);
    customstyle.setFillForegroundColor(title_bg_color);
    customstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    XSSFFont f1 = (XSSFFont) this.excelfile.createFont();
    f1.setColor(title_font_color);
    f1.setBoldweight(Font.BOLDWEIGHT_BOLD);
    customstyle.setFont(f1);
    int cCN = 0;
    for (String s : this.mhColNms) {

        Cell c = colNms.createCell(cCN);
        c.setCellValue(createHelper.createRichTextString(s));
        c.setCellStyle(customstyle);
        cCN++;

    }

    customstyle = (XSSFCellStyle) this.excelfile.createCellStyle();
    customstyle.cloneStyleFrom(cellStyle);
    customstyle.setFillForegroundColor(oddrow_color);
    customstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    for (Match t : this.parser.getMatches()) {

        Row r = this.matchsheet.createRow(rows++);

        int cell = 0;

        for (String s : t.getData()) {

            Cell c = r.createCell(cell);

            c.setCellValue(createHelper.createRichTextString(s));

            if (rows % 2 == 0)
                c.setCellStyle(customstyle);
            else
                c.setCellStyle(cellStyle);

            cell++;

        }

    }

    for (int i = 0; i < length; i++) {

        this.matchsheet.autoSizeColumn(i);

    }

}