Example usage for org.apache.poi.ss.usermodel Font setUnderline

List of usage examples for org.apache.poi.ss.usermodel Font setUnderline

Introduction

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

Prototype


void setUnderline(byte underline);

Source Link

Document

set type of text underlining to use

Usage

From source file:de.jlo.talendcomp.excel.SpreadsheetFile.java

License:Apache License

/**
 * adds a font to the workbook/* w  ww  .ja  v  a  2 s  .c o  m*/
 * @param family like Arial
 * @param height like 8,9,10,12,14...
 * @param bui with "b"=bold, "u"=underlined, "i"=italic and all combinations as String
 * @param color color index
 */
public void addStyle(String styleName, String fontFamily, String fontHeight, String fontDecoration,
        String fontColor, String bgColor, String textAlign, boolean buttomBorder) {
    if (styleName != null && styleName.isEmpty() == false) {
        Font f = workbook.createFont();
        if (fontFamily != null && fontFamily.isEmpty() == false) {
            f.setFontName(fontFamily);
        }
        if (fontHeight != null && fontHeight.isEmpty() == false) {
            short height = Short.parseShort(fontHeight);
            if (height > 0) {
                f.setFontHeightInPoints(height);
            }
        }
        if (fontDecoration != null && fontDecoration.isEmpty() == false) {
            if (fontDecoration.contains("b")) {
                f.setBold(true);
            }
            if (fontDecoration.contains("i")) {
                f.setItalic(true);
            }
            if (fontDecoration.contains("u")) {
                f.setUnderline(Font.U_SINGLE);
            }
        }
        if (fontColor != null && fontColor.isEmpty() == false) {
            short color = Short.parseShort(fontColor);
            f.setColor(color);
        }
        CellStyle style = workbook.createCellStyle();
        style.setFont(f);
        if (bgColor != null && bgColor.isEmpty() == false) {
            short color = Short.parseShort(bgColor);
            style.setFillForegroundColor(color);
            //style.setFillBackgroundColor(color);
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        }
        if (textAlign != null && textAlign.isEmpty() == false) {
            if ("center".equalsIgnoreCase(textAlign)) {
                style.setAlignment(HorizontalAlignment.CENTER);
            } else if ("left".equalsIgnoreCase(textAlign)) {
                style.setAlignment(HorizontalAlignment.LEFT);
            } else if ("right".equals(textAlign)) {
                style.setAlignment(HorizontalAlignment.RIGHT);
            }
        }
        if (buttomBorder) {
            style.setBorderBottom(BorderStyle.MEDIUM);
            style.setBottomBorderColor((short) 9);
        }
        namedStyles.put(styleName, style);
    }
}

From source file:Export.ExporOnlyViagemExcel.java

private void dataTableDados(Workbook wb, Date dataInicio, Date dataFim) throws ParseException {

    Font fTitulo = wb.createFont();
    fTitulo.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD);
    fTitulo.setFontHeightInPoints((short) 14);

    Font fTituloP = wb.createFont();
    fTituloP.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD);
    fTituloP.setFontHeightInPoints((short) 12);
    //            fTituloP.setStrikeout(true);
    fTituloP.setUnderline(org.apache.poi.ss.usermodel.Font.U_SINGLE);

    Font fTituloTabela = wb.createFont();
    fTituloTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD);
    fTituloTabela.setFontHeightInPoints((short) 8);

    Font fCorpoTabela = wb.createFont();
    fCorpoTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_NORMAL);
    fCorpoTabela.setFontHeightInPoints((short) 8.5);

    Font fRodapeTabela = wb.createFont();
    fRodapeTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD);
    fRodapeTabela.setFontHeightInPoints((short) 8.5);

    Font fNormal = wb.createFont();
    fNormal.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD);
    fNormal.setFontHeightInPoints((short) 8.5);

    CellStyle csTitulo = wb.createCellStyle();
    csTitulo.setFont(fTitulo);//from  www. jav  a 2s .  c  o m
    csTitulo.setAlignment((short) 1);
    csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    csTitulo.setBorderBottom((short) 0);
    csTitulo.setBorderTop((short) 0);
    csTitulo.setBorderRight((short) 0);
    csTitulo.setBorderLeft((short) 0);
    csTitulo.setWrapText(true);

    CellStyle csTituloP = wb.createCellStyle();
    csTituloP.setFont(fTituloP);
    csTituloP.setAlignment((short) 1);
    csTituloP.setVerticalAlignment((short) 1);
    csTituloP.setBorderBottom((short) 0);
    csTituloP.setBorderTop((short) 0);
    csTituloP.setBorderRight((short) 0);
    csTituloP.setBorderLeft((short) 0);
    csTituloP.setWrapText(true);

    CellStyle csTituloT = wb.createCellStyle();
    csTituloT.setFont(fTituloP);
    csTituloT.setAlignment((short) 1);
    csTituloT.setVerticalAlignment((short) 1);
    csTituloT.setBorderBottom((short) 0);
    csTituloT.setBorderTop((short) 0);
    csTituloT.setBorderRight((short) 0);
    csTituloT.setBorderLeft((short) 0);
    csTituloT.setWrapText(true);

    CellStyle csTituloTabela = wb.createCellStyle();
    csTituloTabela.setFont(fTituloTabela);
    csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER);
    csTituloTabela.setVerticalAlignment((short) 2);
    csTituloTabela.setBorderBottom((short) 2);
    csTituloTabela.setBorderTop((short) 2);
    csTituloTabela.setBorderRight((short) 2);
    csTituloTabela.setBorderLeft((short) 2);
    csTituloTabela.setWrapText(true);

    CellStyle csTituloTabelaNBorder = wb.createCellStyle();
    csTituloTabelaNBorder.setFont(fTituloTabela);
    csTituloTabelaNBorder.setAlignment(CellStyle.ALIGN_CENTER);
    csTituloTabelaNBorder.setVerticalAlignment((short) 2);
    csTituloTabelaNBorder.setBorderBottom((short) 2);
    csTituloTabelaNBorder.setBorderTop((short) 2);
    csTituloTabelaNBorder.setBorderRight((short) 2);
    csTituloTabelaNBorder.setBorderLeft((short) 2);
    csTituloTabelaNBorder.setWrapText(true);

    CellStyle csCorpoTabela = wb.createCellStyle();
    csCorpoTabela.setFont(fCorpoTabela);
    csCorpoTabela.setAlignment((short) 2);
    csCorpoTabela.setVerticalAlignment((short) 1);
    csCorpoTabela.setBorderBottom((short) 1);
    csCorpoTabela.setBorderTop((short) 1);
    csCorpoTabela.setBorderRight((short) 1);
    csCorpoTabela.setBorderLeft((short) 1);
    csCorpoTabela.setWrapText(true);

    CellStyle csCorpoTabelaR = wb.createCellStyle();
    csCorpoTabelaR.setFont(fCorpoTabela);
    csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT);
    csCorpoTabelaR.setVerticalAlignment((short) 1);
    csCorpoTabelaR.setBorderBottom((short) 1);
    csCorpoTabelaR.setBorderTop((short) 1);
    csCorpoTabelaR.setBorderRight((short) 1);
    csCorpoTabelaR.setBorderLeft((short) 1);
    csCorpoTabelaR.setWrapText(true);

    CellStyle csCorpoTabelaL = wb.createCellStyle();
    csCorpoTabelaL.setFont(fCorpoTabela);
    csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT);
    csCorpoTabelaL.setVerticalAlignment((short) 1);
    csCorpoTabelaL.setBorderBottom((short) 1);
    csCorpoTabelaL.setBorderTop((short) 1);
    csCorpoTabelaL.setBorderRight((short) 1);
    csCorpoTabelaL.setBorderLeft((short) 1);
    csCorpoTabelaL.setWrapText(true);

    CellStyle csRodapeTabela = wb.createCellStyle();
    csRodapeTabela.setFont(fRodapeTabela);
    csRodapeTabela.setAlignment((short) 1);
    csRodapeTabela.setVerticalAlignment((short) 2);
    csRodapeTabela.setBorderBottom((short) 2);
    csRodapeTabela.setBorderTop((short) 2);
    csRodapeTabela.setBorderRight((short) 2);
    csRodapeTabela.setBorderLeft((short) 2);
    csRodapeTabela.setWrapText(true);

    CellStyle csRodapeTabelaR = wb.createCellStyle();
    csRodapeTabelaR.setFont(fRodapeTabela);
    csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT);
    csRodapeTabelaR.setVerticalAlignment((short) 2);
    csRodapeTabelaR.setBorderBottom((short) 2);
    csRodapeTabelaR.setBorderTop((short) 2);
    csRodapeTabelaR.setBorderRight((short) 2);
    csRodapeTabelaR.setBorderLeft((short) 2);
    csRodapeTabelaR.setWrapText(true);

    CellStyle csNomal = wb.createCellStyle();
    csNomal.setFont(fCorpoTabela);
    csNomal.setAlignment((short) 1);
    csNomal.setVerticalAlignment((short) 1);
    csNomal.setBorderBottom((short) 0);
    csNomal.setBorderTop((short) 0);
    csNomal.setBorderRight((short) 0);
    csNomal.setBorderLeft((short) 0);
    csNomal.setWrapText(true);

    int i, p = 0;
    dataViagem(dataInicio, dataFim);
    for (Map.Entry<String, ArrayList<HashMap<String, Object>>> data : hasList.entrySet()) {

        totalSelo = 0f;
        totalConsumo = 0f;
        totalTotal = 0f;
        totalPremio = 0f;
        totalComissao = 0f;

        linha = 0;

        SimpleDateFormat sdfEsp = new SimpleDateFormat("MMMM, yyyy", Locale.ENGLISH);
        SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy");

        String titile = sdfEsp.format(sdf.parse((data.getKey()))).toUpperCase();

        Sheet s = wb.createSheet(titile);

        dataTableTitile(s, titile, csTitulo, csTituloP, csTituloTabelaNBorder);

        Row r = s.createRow(linha);
        Cell c = r.createCell(2);

        for (int j = 0; j < 13; j++) {
            switch (j) {
            case 0:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 1, 4);
                break;
            case 1:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 2, 6);
                break;
            case 2:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 3, 8);
                break;
            case 3:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 4, 6);
                break;
            case 4:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 5, 6);
                break;
            case 5:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 6, 4);
                break;
            case 6:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 7, 25);
                break;
            case 7:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 8, 10);
                break;
            case 8:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 9, 10);
                break;
            case 9:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 10, 8);
                break;
            case 10:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 11, 8);
                break;
            case 11:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 12, 8);
                break;
            case 12:
                createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 13, 8);
                break;
            default:
                break;
            }
        }
        i = 1;

        for (HashMap<String, Object> hashMap : data.getValue()) {

            linha++;
            r = s.createRow(linha);
            c = r.createCell(2);

            createCell(c, r, s, csCorpoTabela, linha, linha, (i + ""), 1, 4);

            createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(DATA)), 2, 6);

            createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(NUMEROAPOLICE)), 3, 7);

            createCell(c, r, s, csCorpoTabela, linha, linha,
                    ConfigDoc.toFormat(toString(hashMap.get(INICIO)), "dd-MM-yyyy", "yyyy-MM-dd"), 4, 6);

            createCell(c, r, s, csCorpoTabela, linha, linha,
                    ConfigDoc.toFormat(toString(hashMap.get(FIM)), "dd-MM-yyyy", "yyyy-MM-dd"), 5, 6);

            createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(DIAS)), 6, 4);

            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(hashMap.get(CLIENTE)), 7, 20);

            createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(RECIBO)), 8, 10);

            createCell(c, r, s, csCorpoTabelaR, linha, linha, toString(hashMap.get(PREMIO)), 9, 10);

            totalComissao += toFloat(toString(hashMap.get(COMISSAO)));
            createCell(c, r, s, csCorpoTabelaR, linha, linha,
                    ConfigDoc.toMoeda(toString(hashMap.get(COMISSAO)), ""), 10, 8);

            totalConsumo += toFloat(toString(hashMap.get(CONSUMO)));
            createCell(c, r, s, csCorpoTabelaR, linha, linha,
                    ConfigDoc.toMoeda(toString(hashMap.get(CONSUMO)), ""), 11, 8);

            totalSelo += toFloat(toString(hashMap.get(SELO)));
            createCell(c, r, s, csCorpoTabelaR, linha, linha,
                    ConfigDoc.toMoeda(toString(hashMap.get(SELO)), ""), 12, 8);

            totalTotal += toFloat(toString(hashMap.get(TOTAL)));
            createCell(c, r, s, csCorpoTabelaR, linha, linha,
                    ConfigDoc.toMoeda(toString(hashMap.get(TOTAL)), ""), 13, 8);

            i++;
        }
        linha++;
        radapeTable(s, csRodapeTabelaR);
    }
}

From source file:Export.ExportViagemSemanaExcel.java

public static void criarDoc(Date dataInicio, Date dateFim, String user, String nomeFuncinario) {
    Workbook wb = new HSSFWorkbook();

    Font fTitulo = wb.createFont();
    fTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD);
    fTitulo.setFontHeightInPoints((short) 14);

    Font fTituloP = wb.createFont();
    fTituloP.setBoldweight(Font.BOLDWEIGHT_BOLD);
    fTituloP.setFontHeightInPoints((short) 12);
    //            fTituloP.setStrikeout(true);
    fTituloP.setUnderline(Font.U_SINGLE);

    Font fTituloTabela = wb.createFont();
    fTituloTabela.setBoldweight(Font.BOLDWEIGHT_BOLD);
    fTituloTabela.setFontHeightInPoints((short) 8);

    Font fCorpoTabela = wb.createFont();
    fCorpoTabela.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    fCorpoTabela.setFontHeightInPoints((short) 8.5);

    Font fRodapeTabela = wb.createFont();
    fRodapeTabela.setBoldweight(Font.BOLDWEIGHT_BOLD);
    fRodapeTabela.setFontHeightInPoints((short) 8.5);

    Font fNormal = wb.createFont();
    fNormal.setBoldweight(Font.BOLDWEIGHT_BOLD);
    fNormal.setFontHeightInPoints((short) 8.5);

    CellStyle csTitulo = wb.createCellStyle();
    csTitulo.setFont(fTitulo);//ww  w. j ava  2 s  .c o  m
    csTitulo.setAlignment((short) 1);
    csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    csTitulo.setBorderBottom((short) 0);
    csTitulo.setBorderTop((short) 0);
    csTitulo.setBorderRight((short) 0);
    csTitulo.setBorderLeft((short) 0);
    csTitulo.setWrapText(true);

    CellStyle csTituloP = wb.createCellStyle();
    csTituloP.setFont(fTituloP);
    csTituloP.setAlignment((short) 1);
    csTituloP.setVerticalAlignment((short) 1);
    csTituloP.setBorderBottom((short) 0);
    csTituloP.setBorderTop((short) 0);
    csTituloP.setBorderRight((short) 0);
    csTituloP.setBorderLeft((short) 0);
    csTituloP.setWrapText(true);

    CellStyle csTituloT = wb.createCellStyle();
    csTituloT.setFont(fTituloP);
    csTituloT.setAlignment((short) 1);
    csTituloT.setVerticalAlignment((short) 1);
    csTituloT.setBorderBottom((short) 0);
    csTituloT.setBorderTop((short) 0);
    csTituloT.setBorderRight((short) 0);
    csTituloT.setBorderLeft((short) 0);
    csTituloT.setWrapText(true);

    CellStyle csTituloTabela = wb.createCellStyle();
    csTituloTabela.setFont(fTituloTabela);
    csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER);
    csTituloTabela.setVerticalAlignment((short) 2);
    csTituloTabela.setBorderBottom((short) 2);
    csTituloTabela.setBorderTop((short) 2);
    csTituloTabela.setBorderRight((short) 2);
    csTituloTabela.setBorderLeft((short) 2);
    csTituloTabela.setWrapText(true);

    CellStyle csTituloTabelaNBorder = wb.createCellStyle();
    csTituloTabelaNBorder.setFont(fTituloTabela);
    csTituloTabelaNBorder.setAlignment(CellStyle.ALIGN_CENTER);
    csTituloTabelaNBorder.setVerticalAlignment((short) 2);
    csTituloTabelaNBorder.setBorderBottom((short) 2);
    csTituloTabelaNBorder.setBorderTop((short) 2);
    csTituloTabelaNBorder.setBorderRight((short) 2);
    csTituloTabelaNBorder.setBorderLeft((short) 2);
    csTituloTabelaNBorder.setWrapText(true);

    CellStyle csCorpoTabela = wb.createCellStyle();
    csCorpoTabela.setFont(fCorpoTabela);
    csCorpoTabela.setAlignment((short) 2);
    csCorpoTabela.setVerticalAlignment((short) 1);
    csCorpoTabela.setBorderBottom((short) 1);
    csCorpoTabela.setBorderTop((short) 1);
    csCorpoTabela.setBorderRight((short) 1);
    csCorpoTabela.setBorderLeft((short) 1);
    csCorpoTabela.setWrapText(true);

    CellStyle csCorpoTabelaR = wb.createCellStyle();
    csCorpoTabelaR.setFont(fCorpoTabela);
    csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT);
    csCorpoTabelaR.setVerticalAlignment((short) 1);
    csCorpoTabelaR.setBorderBottom((short) 1);
    csCorpoTabelaR.setBorderTop((short) 1);
    csCorpoTabelaR.setBorderRight((short) 1);
    csCorpoTabelaR.setBorderLeft((short) 1);
    csCorpoTabelaR.setWrapText(true);

    CellStyle csCorpoTabelaL = wb.createCellStyle();
    csCorpoTabelaL.setFont(fCorpoTabela);
    csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT);
    csCorpoTabelaL.setVerticalAlignment((short) 1);
    csCorpoTabelaL.setBorderBottom((short) 1);
    csCorpoTabelaL.setBorderTop((short) 1);
    csCorpoTabelaL.setBorderRight((short) 1);
    csCorpoTabelaL.setBorderLeft((short) 1);
    csCorpoTabelaL.setWrapText(true);

    CellStyle csRodapeTabela = wb.createCellStyle();
    csRodapeTabela.setFont(fRodapeTabela);
    csRodapeTabela.setAlignment((short) 1);
    csRodapeTabela.setVerticalAlignment((short) 2);
    csRodapeTabela.setBorderBottom((short) 2);
    csRodapeTabela.setBorderTop((short) 2);
    csRodapeTabela.setBorderRight((short) 2);
    csRodapeTabela.setBorderLeft((short) 2);
    csRodapeTabela.setWrapText(true);

    CellStyle csRodapeTabelaR = wb.createCellStyle();
    csRodapeTabelaR.setFont(fRodapeTabela);
    csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT);
    csRodapeTabelaR.setVerticalAlignment((short) 2);
    csRodapeTabelaR.setBorderBottom((short) 2);
    csRodapeTabelaR.setBorderTop((short) 2);
    csRodapeTabelaR.setBorderRight((short) 2);
    csRodapeTabelaR.setBorderLeft((short) 2);
    csRodapeTabelaR.setWrapText(true);

    CellStyle csNomal = wb.createCellStyle();
    csNomal.setFont(fCorpoTabela);
    csNomal.setAlignment((short) 1);
    csNomal.setVerticalAlignment((short) 1);
    csNomal.setBorderBottom((short) 0);
    csNomal.setBorderTop((short) 0);
    csNomal.setBorderRight((short) 0);
    csNomal.setBorderLeft((short) 0);
    csNomal.setWrapText(true);

    OutputStream outputStraem;
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh.mm.ss");
        SimpleDateFormat sdfTitile = new SimpleDateFormat("dd-MM-yyyy");

        File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Seguro Viagem/");
        ff.mkdirs();

        String Ddata = sdf.format(new Date());

        ff = new File(ff.getAbsoluteFile() + "/" + "Export Mapa Viagem Semanal " + Ddata + ".xls");
        String reString = "../Documentos/" + user + "/Seguro Viagem/" + "Export Mapa Viagem Semanal " + Ddata
                + ".xls";
        outputStraem = new FileOutputStream(ff);

        int linha = 0;

        Sheet s = wb.createSheet("RELATORIO SEMANAL");

        Row r = s.createRow(linha);
        Cell c = r.createCell(2);
        createCellM(c, r, s, csTitulo, linha, linha + 3, ConfigDoc.Empresa.NOME, 1, 22);
        linha += 4;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.ENDERECO, 1, 22);
        linha++;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.CAIXAPOSTAL, 1, 22);
        linha++;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL,
                1, 22);
        linha++;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.SOCIEDADE, 1, 22);
        linha += 3;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloTabelaNBorder, linha, linha + 1,
                "RELATORIO SEMANAL NO. " + "" + "\n"
                        + ((dataInicio != null) ? sdfTitile.format(dataInicio) + " - " : "")
                        + ((dateFim != null) ? sdfTitile.format(dateFim) : ""),
                1, 10);
        linha += 3;

        r = s.createRow(linha);
        c = r.createCell(2);

        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(0), 1, 4); //1
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(1), 2, 6); //2
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(2), 3, 6); //1
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(3), 4, 6); //1
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(4), 5, 6); //2
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(5), 6, 20); //3
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(6), 7, 4); //1
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(7), 8, 4); //1
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(8), 9, 8); //2
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(9), 10, 8); //1
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(10), 11, 6); //2
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(11), 12, 6); //2
        createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(12), 13, 6); //2

        dataViagem(dataInicio, dateFim);

        float premiototal = 0;

        linha++;
        for (HashMap<String, Object> data : hasList) {

            linha++;
            r = s.createRow(linha);
            c = r.createCell(2);

            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(DATA)), 1, 4);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(NUMEROAPOLICE)), 2, 6);
            createCell(c, r, s, csCorpoTabelaL, linha, linha,
                    ConfigDoc.toFormat(toString(data.get(INICIO)), "dd-MM-yyyy", "yyyy-MM-dd"), 3, 6);
            createCell(c, r, s, csCorpoTabelaL, linha, linha,
                    ConfigDoc.toFormat(toString(data.get(FIM)), "dd-MM-yyyy", "yyyy-MM-dd"), 4, 6);

            premiototal += toFloat(data.get(PREMIO));
            createCell(c, r, s, csCorpoTabelaR, linha, linha, ConfigDoc.toMoeda(toFloat(data.get(PREMIO)), ""),
                    5, 6);

            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(CLIENTE)), 6, 20);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(DATANASCIMENTO)), 7, 4);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(TELEFONE)), 8, 4);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(ENDERECO)), 9, 8);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(LOCALNASCIMENTO)), 10, 8);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(PAISDESTINO)), 11, 6);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(CIDADEDESTINO)), 12, 6);
            createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(ZONADESTINO)), 13, 6);

        }

        linha++;
        r = s.createRow(linha);
        c = r.createCell(2);

        createCellM(c, r, s, csRodapeTabela, linha, linha,
                "AL AMOUNT..........................................", 1, 5);

        createCellM(c, r, s, csRodapeTabelaR, linha, linha, ConfigDoc.toMoeda(premiototal, ""), 6, 7);

        createCellM(c, r, s, csRodapeTabela, linha, linha, " ", 8, 13);

        try (FileOutputStream out = new FileOutputStream(ff)) {
            wb.write(out);
        } catch (IOException ex) {
            Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex);
        }

        RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')");

    } catch (FileNotFoundException ex) {
        Logger.getLogger(ExportViagemSemanaExcel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Export.GenericExcel.java

/**
 *
 * @param user/*from  w ww .j  a  v a2  s  .c  om*/
 * @param nomeDoc
 * @param titleDoc
 * @param rs
 * @param paramFilter
 * @return
 */
public static String createDoc(String user, String nomeDoc, String titleDoc, DataTableControl rs,
        int paramFilter) {

    OutputStream outputStraem = null;
    try {
        i = 0;
        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");
        File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio");
        ff.mkdirs();
        String Ddata = sdf1.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + nomeDoc + " " + Ddata + ".xls");
        outputStraem = new FileOutputStream(ff);
        reString = "../Documentos/" + user + "/Relatorio/" + nomeDoc + " " + Ddata + ".xls";

        getMap(rs, paramFilter);
        float[] colun = createPerncetage(list, paramFilter);

        Workbook wb = new HSSFWorkbook();

        Font fTitulo = wb.createFont();
        fTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD);
        fTitulo.setFontHeightInPoints((short) 14);

        Font fTituloP = wb.createFont();
        fTituloP.setBoldweight(Font.BOLDWEIGHT_BOLD);
        fTituloP.setFontHeightInPoints((short) 12);
        fTituloP.setUnderline(Font.U_SINGLE);

        Font fTituloTabela = wb.createFont();
        fTituloTabela.setBoldweight(Font.BOLDWEIGHT_BOLD);
        fTituloTabela.setFontHeightInPoints((short) 8);

        Font fCorpoTabela = wb.createFont();
        fCorpoTabela.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        fCorpoTabela.setFontHeightInPoints((short) 8.5);

        Font fRodapeTabela = wb.createFont();
        fRodapeTabela.setBoldweight(Font.BOLDWEIGHT_BOLD);
        fRodapeTabela.setFontHeightInPoints((short) 8.5);

        Font fNormal = wb.createFont();
        fNormal.setBoldweight(Font.BOLDWEIGHT_BOLD);
        fNormal.setFontHeightInPoints((short) 8.5);

        CellStyle csTitulo = wb.createCellStyle();
        csTitulo.setFont(fTitulo);
        csTitulo.setAlignment((short) 1);
        csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
        csTitulo.setBorderBottom((short) 0);
        csTitulo.setBorderTop((short) 0);
        csTitulo.setBorderRight((short) 0);
        csTitulo.setBorderLeft((short) 0);
        csTitulo.setWrapText(true);

        CellStyle csTituloP = wb.createCellStyle();
        csTituloP.setFont(fTituloP);
        csTituloP.setAlignment((short) 1);
        csTituloP.setVerticalAlignment((short) 1);
        csTituloP.setBorderBottom((short) 0);
        csTituloP.setBorderTop((short) 0);
        csTituloP.setBorderRight((short) 0);
        csTituloP.setBorderLeft((short) 0);
        csTituloP.setWrapText(true);

        CellStyle csTituloT = wb.createCellStyle();
        csTituloT.setFont(fTituloP);
        csTituloT.setAlignment((short) 1);
        csTituloT.setVerticalAlignment((short) 1);
        csTituloT.setBorderBottom((short) 0);
        csTituloT.setBorderTop((short) 0);
        csTituloT.setBorderRight((short) 0);
        csTituloT.setBorderLeft((short) 0);
        csTituloT.setWrapText(true);

        CellStyle csTituloTabela = wb.createCellStyle();
        csTituloTabela.setFont(fTituloTabela);
        csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER);
        csTituloTabela.setVerticalAlignment((short) 2);
        csTituloTabela.setBorderBottom((short) 2);
        csTituloTabela.setBorderTop((short) 2);
        csTituloTabela.setBorderRight((short) 2);
        csTituloTabela.setBorderLeft((short) 2);
        csTituloTabela.setWrapText(true);

        CellStyle csTituloTabelaNBorder = wb.createCellStyle();
        csTituloTabelaNBorder.setFont(fTituloTabela);
        csTituloTabelaNBorder.setAlignment(CellStyle.ALIGN_CENTER);
        csTituloTabelaNBorder.setVerticalAlignment((short) 2);
        csTituloTabelaNBorder.setBorderBottom((short) 2);
        csTituloTabelaNBorder.setBorderTop((short) 2);
        csTituloTabelaNBorder.setBorderRight((short) 2);
        csTituloTabelaNBorder.setBorderLeft((short) 2);
        csTituloTabelaNBorder.setWrapText(true);

        CellStyle csCorpoTabela = wb.createCellStyle();
        csCorpoTabela.setFont(fCorpoTabela);
        csCorpoTabela.setAlignment((short) 2);
        csCorpoTabela.setVerticalAlignment((short) 1);
        csCorpoTabela.setBorderBottom((short) 1);
        csCorpoTabela.setBorderTop((short) 1);
        csCorpoTabela.setBorderRight((short) 1);
        csCorpoTabela.setBorderLeft((short) 1);
        csCorpoTabela.setWrapText(true);

        CellStyle csCorpoTabelaR = wb.createCellStyle();
        csCorpoTabelaR.setFont(fCorpoTabela);
        csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT);
        csCorpoTabelaR.setVerticalAlignment((short) 1);
        csCorpoTabelaR.setBorderBottom((short) 1);
        csCorpoTabelaR.setBorderTop((short) 1);
        csCorpoTabelaR.setBorderRight((short) 1);
        csCorpoTabelaR.setBorderLeft((short) 1);
        csCorpoTabelaR.setWrapText(true);

        CellStyle csCorpoTabelaL = wb.createCellStyle();
        csCorpoTabelaL.setFont(fCorpoTabela);
        csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT);
        csCorpoTabelaL.setVerticalAlignment((short) 1);
        csCorpoTabelaL.setBorderBottom((short) 1);
        csCorpoTabelaL.setBorderTop((short) 1);
        csCorpoTabelaL.setBorderRight((short) 1);
        csCorpoTabelaL.setBorderLeft((short) 1);
        csCorpoTabelaL.setWrapText(true);

        CellStyle csRodapeTabelaL = wb.createCellStyle();
        csRodapeTabelaL.setFont(fRodapeTabela);
        csRodapeTabelaL.setAlignment(CellStyle.ALIGN_CENTER);
        csRodapeTabelaL.setVerticalAlignment((short) 2);
        csRodapeTabelaL.setBorderBottom((short) 2);
        csRodapeTabelaL.setBorderTop((short) 2);
        csRodapeTabelaL.setBorderRight((short) 2);
        csRodapeTabelaL.setBorderLeft((short) 2);
        csRodapeTabelaL.setWrapText(true);

        CellStyle csRodapeTabela = wb.createCellStyle();
        csRodapeTabela.setFont(fRodapeTabela);
        csRodapeTabela.setAlignment(CellStyle.ALIGN_CENTER);
        csRodapeTabela.setVerticalAlignment((short) 2);
        csRodapeTabela.setBorderBottom((short) 2);
        csRodapeTabela.setBorderTop((short) 2);
        csRodapeTabela.setBorderRight((short) 2);
        csRodapeTabela.setBorderLeft((short) 2);
        csRodapeTabela.setWrapText(true);

        CellStyle csRodapeTabelaR = wb.createCellStyle();
        csRodapeTabelaR.setFont(fRodapeTabela);
        csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT);
        csRodapeTabelaR.setVerticalAlignment((short) 2);
        csRodapeTabelaR.setBorderBottom((short) 2);
        csRodapeTabelaR.setBorderTop((short) 2);
        csRodapeTabelaR.setBorderRight((short) 2);
        csRodapeTabelaR.setBorderLeft((short) 2);
        csRodapeTabelaR.setWrapText(true);

        CellStyle csNomal = wb.createCellStyle();
        csNomal.setFont(fCorpoTabela);
        csNomal.setAlignment((short) 1);
        csNomal.setVerticalAlignment((short) 1);
        csNomal.setBorderBottom((short) 0);
        csNomal.setBorderTop((short) 0);
        csNomal.setBorderRight((short) 0);
        csNomal.setBorderLeft((short) 0);
        csNomal.setWrapText(true);

        Sheet s = wb.createSheet(titleDoc);

        linha = 0;

        Row r = s.createRow(linha);
        Cell c = r.createCell(2);
        createCellM(c, r, s, csTitulo, linha, linha + 3, ConfigDoc.Empresa.NOME, 1, 22);
        linha += 4;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.ENDERECO, 1, 22);
        linha++;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.CAIXAPOSTAL, 1, 22);
        linha++;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL,
                1, 22);
        linha++;

        r = s.createRow(linha);
        createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.SOCIEDADE, 1, 22);
        linha += 3;

        r = s.createRow(linha);
        SimpleDateFormat format = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR"));
        createCellM(c, r, s, csTituloT, linha, linha,
                titleDoc.toUpperCase() + ((dF != null && dI != null)
                        ? (" de " + format.format(dI) + "  " + format.format(dF)).toUpperCase()
                        : ""),
                1, 22);
        linha += 2;
        if (paramFilter < 0) {
            for (Object[] emap : list) {
                k = 0;
                r = s.createRow(linha);
                for (int j = 0; j < emap.length; j++) {
                    if (j != paramFilterOculta) {
                        if (i == 0) {
                            lista_titulo_table = emap;
                            csCorpoTabela.setFillBackgroundColor(HSSFColor.BLUE.index);
                            createCell(c, r, s, csTituloTabela, linha, linha, toString(emap[j]), k + 1,
                                    toInt(colun[k]));
                            k++;
                        } else {
                            csCorpoTabelaL.setFillBackgroundColor(
                                    ((i % 2) == 0) ? HSSFColor.WHITE.index : HSSFColor.GREY_25_PERCENT.index);
                            createCell(c, r, s,
                                    ((alignment.containsKey(j))
                                            ? ((alignment.get(j) == Alignment.RIGHT) ? csCorpoTabelaR
                                                    : ((alignment.get(j) == Alignment.CENTER) ? csCorpoTabela
                                                            : csCorpoTabelaL))
                                            : csCorpoTabelaL),
                                    linha, linha, toString(emap[j]), k + 1, toInt(colun[k]));
                            k++;
                        }
                    }
                }
                i++;
                linha++;
            }
            for (Map.Entry<String, ArrayList<Object[]>> entrySet : mapTotal.entrySet()) {
                for (Object[] emapT : entrySet.getValue()) {
                    k = 0;
                    r = s.createRow(linha);
                    for (int j = 0; j < emapT.length; j++) {
                        if (j != paramFilterOculta) {
                            csCorpoTabelaL.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index);
                            createCell(c, r, s,
                                    ((alignment.containsKey(j))
                                            ? ((alignment.get(j) == Alignment.RIGHT) ? csRodapeTabelaR
                                                    : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabelaR
                                                            : csRodapeTabelaL))
                                            : csRodapeTabelaL),
                                    linha, linha, ((j == 0) ? "TOTAL" : toString(emapT[j])), k + 1,
                                    toInt(colun[k]));
                            k++;
                        }
                    }
                }
            }
        } else {
            int t = 0;
            for (Map.Entry<String, ArrayList<Object[]>> lista : map.entrySet()) {
                r = s.createRow(linha);
                csTituloTabela.setFillBackgroundColor(HSSFColor.WHITE.index);
                createCellM(c, r, s, csTituloTabelaNBorder, linha, linha, toString(lista.getKey()), 1, 7);
                linha += 2;
                for (Object[] emap : lista.getValue()) {
                    k = 0;
                    r = s.createRow(linha);
                    for (int j = 0; j < emap.length; j++) {
                        if (j != paramFilterOculta) {
                            if (i == 0) {
                                lista_titulo_table = emap;
                                csTituloTabela.setFillBackgroundColor(HSSFColor.BLUE.index);
                                createCell(c, r, s, csTituloTabela, linha, linha, toString(emap[j]), k + 1,
                                        toInt(colun[k]));
                                k++;
                            } else {
                                csCorpoTabelaL.setFillBackgroundColor(((i % 2) == 0) ? HSSFColor.WHITE.index
                                        : HSSFColor.GREY_25_PERCENT.index);
                                createCell(c, r, s,
                                        ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT)
                                                ? csCorpoTabelaR
                                                : ((alignment.get(j) == Alignment.CENTER) ? csCorpoTabela
                                                        : csCorpoTabelaL))
                                                : csCorpoTabelaL),
                                        linha, linha, toString(emap[j]), k + 1, toInt(colun[k]));
                                k++;
                            }
                        }

                    }
                    i++;
                    linha++;
                }

                if (mapTotal.containsKey(lista.getKey())) {
                    for (Object[] emapT : mapTotal.get(lista.getKey())) {
                        k = 0;
                        r = s.createRow(linha);
                        for (int j = 0; j < emapT.length; j++) {
                            if (j != paramFilterOculta) {
                                createCell(c, r, s,
                                        ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT)
                                                ? csRodapeTabelaR
                                                : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabela
                                                        : csRodapeTabelaL))
                                                : csRodapeTabelaL),
                                        linha, linha, ((j == 0) ? "TOTAL" : toString(emapT[j])), k + 1,
                                        toInt(colun[k]));
                                k++;
                            }
                        }
                    }
                }
                t++;
                i = 0;
                linha += 3;
                if (t == map.size() && paramFilter > -1) {
                    k = 0;
                    r = s.createRow(linha);
                    for (int j = 0; j < lista_titulo_table.length; j++) {
                        if (j != paramFilterOculta) {
                            csTituloTabela.setFillBackgroundColor(HSSFColor.BLUE.index);
                            createCell(c, r, s, csTituloTabela, linha, linha, toString(lista_titulo_table[j]),
                                    k + 1, toInt(colun[k]));
                            k++;
                        }
                    }
                    linha++;
                    Double[] total_total = new Double[lista_titulo_table.length];
                    for (Map.Entry<String, ArrayList<Object[]>> lista_for_total : map.entrySet()) {
                        String key = lista_for_total.getKey();
                        for (Object[] emapT : mapTotal.get(key)) {
                            k = 0;
                            r = s.createRow(linha);
                            for (int j = 0; j < emapT.length; j++) {
                                if (j != paramFilterOculta) {
                                    if (Moeda.unFormat(toString(emapT[j]).replaceAll(" ", "")
                                            .replaceAll(",", ".").replaceAll("STD", "")) != -1) {
                                        Double v = ((total_total[j] == null) ? 0.0 : total_total[j]);
                                        total_total[j] = Moeda.unFormat(toString(emapT[j]).replaceAll(" ", "")
                                                .replaceAll(",", ".").replaceAll("STD", "")) + v;
                                    }
                                    createCell(c, r, s,
                                            ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT)
                                                    ? csRodapeTabelaR
                                                    : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabela
                                                            : csRodapeTabelaL))
                                                    : csRodapeTabelaL),
                                            linha, linha,
                                            ((j == 0) ? "TOTAL " + key.toUpperCase() : toString(emapT[j])),
                                            k + 1, toInt(colun[k]));
                                    k++;
                                }
                            }
                        }
                        linha++;
                    }
                    k = 0;
                    r = s.createRow(linha);
                    for (int j = 0; j < total_total.length; j++) {
                        if (j != paramFilterOculta) {
                            csTituloTabela.setFillBackgroundColor(HSSFColor.BLUE.index);
                            createCell(c, r, s,
                                    ((alignment.containsKey(j))
                                            ? ((alignment.get(j) == Alignment.RIGHT) ? csRodapeTabelaR
                                                    : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabela
                                                            : csRodapeTabelaL))
                                            : csRodapeTabelaL),
                                    linha, linha,
                                    (total_total[j] != null) ? Moeda.format_are(total_total[j]) : " ", k + 1,
                                    toInt(colun[k]));
                            k++;
                        }
                    }
                }
            }

        }

        try (FileOutputStream out = new FileOutputStream(ff)) {
            wb.write(out);
        } catch (IOException ex) {
            Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex);
        }

        RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')");
        no = false;
        nomeNo = "";
        dI = null;
        dF = null;
        paramFilterOculta = -1;
        removeItem = new int[] {};
        renameItem = new HashMap<>();
        alignment = new HashMap<>();
        valoresTotal = new String[] {};
        arrValoresTotal = new int[] {};
        return reString;
    } catch (FileNotFoundException ex) {
        Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex);
        return reString;
    }
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Initialisation des polices//from   w ww .  j a v a 2  s .  c  om
 */
protected void initFonts() {
    Font fontHeader = workbook.createFont();
    fontHeader.setFontHeightInPoints(getHeaderFontHeight());
    fontHeader.setFontName(getFontName());
    fontHeader.setBoldweight(Font.BOLDWEIGHT_BOLD);
    setFontColor(fontHeader, colorRegistry, HEADER_FONT_COLOR_INDEX);
    registerFont(FONT_HEADER_NAME, fontHeader);

    Font fontNormal = workbook.createFont();
    fontNormal.setFontHeightInPoints(getNormalFontHeight());
    fontNormal.setFontName(getFontName());
    registerFont(FONT_NORMAL_NAME, fontNormal);

    Font fontLink = workbook.createFont();
    fontLink.setFontHeightInPoints(getNormalFontHeight());
    fontLink.setFontName(getFontName());
    fontLink.setUnderline(Font.U_SINGLE);
    setFontColor(fontLink, colorRegistry, LINK_FONT_COLOR_INDEX);
    registerFont(FONT_LINK_NAME, fontLink);
}

From source file:guru.qas.martini.report.DefaultState.java

License:Apache License

protected void colorCompromisedThemes() {
    Collection<Cell> failed = statii.get("FAILED");

    if (!failed.isEmpty()) {
        List<Row> rows = Lists.newArrayListWithExpectedSize(failed.size());
        for (Cell cell : failed) {
            Row row = cell.getRow();/* w  w w.  j  a  va  2 s  .  c  o m*/
            rows.add(row);
        }

        Set<Cell> compromisedThemeCells = Sets.newHashSet();

        Map<String, Collection<Cell>> themeMap = themes.asMap();
        for (Map.Entry<String, Collection<Cell>> mapEntry : themeMap.entrySet()) {
            Collection<Cell> themeCells = mapEntry.getValue();

            boolean compromised = false;
            for (Iterator<Cell> iterator = themeCells.iterator(); !compromised && iterator.hasNext();) {
                Cell themeCell = iterator.next();
                Row row = themeCell.getRow();
                compromised = rows.contains(row);
            }

            if (compromised) {
                compromisedThemeCells.addAll(themeCells);
            }
        }

        Set<String> compromisedThemes = Sets.newHashSet();
        for (Cell themeCell : compromisedThemeCells) {
            String contents = themeCell.getStringCellValue();
            if (null != contents) {
                Iterable<String> themes = Splitter.onPattern("\\s+").omitEmptyStrings().split(contents);
                Iterables.addAll(compromisedThemes, themes);
            }
        }

        for (String theme : compromisedThemes) {
            Collection<Cell> cells = themes.get(theme);
            for (Cell cell : cells) {
                CellStyle cellStyle = cell.getCellStyle();
                Sheet sheet = cell.getSheet();
                Workbook workbook = sheet.getWorkbook();

                int originalFontIndex = cellStyle.getFontIndexAsInt();
                Font originalFont = workbook.getFontAt(originalFontIndex);

                CellStyle clone = workbook.createCellStyle();
                clone.cloneStyleFrom(cellStyle);

                Font font = workbook.findFont(true, IndexedColors.DARK_RED.getIndex(),
                        originalFont.getFontHeight(), originalFont.getFontName(), originalFont.getItalic(),
                        originalFont.getStrikeout(), originalFont.getTypeOffset(), originalFont.getUnderline());

                if (null == font) {
                    font = workbook.createFont();
                    font.setBold(true);
                    font.setColor(IndexedColors.DARK_RED.getIndex());
                    font.setFontHeight(originalFont.getFontHeight());
                    font.setFontName(originalFont.getFontName());
                    font.setItalic(originalFont.getItalic());
                    font.setStrikeout(originalFont.getStrikeout());
                    font.setTypeOffset(originalFont.getTypeOffset());
                    font.setUnderline(originalFont.getUnderline());
                }
                clone.setFont(font);
                cell.setCellStyle(clone);
            }
        }
    }
}

From source file:guru.qas.martini.report.DefaultTraceabilityMatrix.java

License:Apache License

protected Font getHeaderFont(Workbook workbook) {
    Font font = workbook.findFont(true, // bold
            IndexedColors.BLACK.getIndex(), (short) 300, ARIAL, false, // italic
            false, // strikeout
            Font.SS_NONE, Font.U_NONE);

    if (null == font) {
        font = workbook.createFont();/*from   w w w  .  j a v  a 2  s  .  c o  m*/
        font.setBold(true);
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setFontHeight((short) 300);
        font.setFontName(ARIAL);
        font.setItalic(false);
        font.setStrikeout(false);
        font.setTypeOffset(Font.SS_NONE);
        font.setUnderline(Font.U_NONE);
    }
    return font;
}

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

License:Apache License

private Font getFont(short fontIndex, AttributeSet attributeSet, Workbook wb) {
    Font font = null;
    String family = null;//from  w  ww .j  a  v  a2s . com
    String sizeStr = null;
    short color = 0;
    boolean bold = false;
    boolean italic = false;
    boolean underline = false;
    boolean line_through = false;
    boolean sub = false;
    boolean sup = false;
    Enumeration<?> en = attributeSet.getAttributeNames();
    while (en.hasMoreElements()) {
        Object key = en.nextElement();
        String name = key.toString();
        String attribute = attributeSet.getAttribute(key).toString();

        switch (name) {
        case "font-weight":
            bold = attribute.equals("bold");
            break;
        case "font-style":
            italic = attribute.equals("italic");
            break;
        case "text-decoration":
            if (attribute.equals("underline")) {
                underline = true;
            } else if (attribute.equals("line-through")) {
                line_through = true;
            }
            break;
        case "font-family":
            family = attribute;
            break;
        case "font-size":
            sizeStr = attribute;

            break;
        case "color":
            Color fontColor = Utils.colorByName(attribute);
            if (fontColor == null) {
                try {
                    fontColor = Utils.stringToColor(attribute);
                } catch (Exception ignored) {

                }
            }
            if (fontColor != null) {
                color = colorToIndex(wb, fontColor);
            }
            break;
        case "vertical-align":
            if (attribute.equals("sub")) {
                sub = true;
            } else if (attribute.equals("sup")) {
                sup = true;
            }
            break;
        }
    }
    if (family != null || bold || italic || underline || line_through || color > 0 || sizeStr != null || sub
            || sup) {

        font = wb.createFont();
        if (fontIndex > 0) {
            Font parentFont = wb.getFontAt(fontIndex);
            if (parentFont != null) {
                font.setBold(parentFont.getBold());
                font.setColor(parentFont.getColor());
                try {
                    font.setCharSet(parentFont.getCharSet());
                } catch (Throwable ignored) {
                }
                font.setFontHeight(parentFont.getFontHeight());
                font.setFontName(parentFont.getFontName());
                font.setItalic(parentFont.getItalic());
                font.setStrikeout(parentFont.getStrikeout());
                font.setUnderline(parentFont.getUnderline());
                font.setTypeOffset(parentFont.getTypeOffset());
            }
        }
        if (family != null) {
            font.setFontName(family);
        }
        if (bold) {
            font.setBold(true);
        }
        if (italic) {
            font.setItalic(italic);
        }
        if (underline) {
            font.setUnderline(Font.U_SINGLE);
        }
        if (line_through) {
            font.setStrikeout(line_through);
        }
        if (color > 0) {
            font.setColor(color);
        }
        if (sizeStr != null) {
            short size = (short) Float.parseFloat(sizeStr);
            if (sizeStr.charAt(0) == '+' || sizeStr.charAt(0) == '-') {
                size = (short) (Content.pointToSize(font.getFontHeightInPoints()) + size);
            }
            font.setFontHeightInPoints(Content.sizeToPoints(size));
        }
        if (sup) {
            font.setTypeOffset(Font.SS_SUPER);
        } else if (sub) {
            font.setTypeOffset(Font.SS_SUB);
        }
    }
    return font;
}

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

License:Apache License

protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) {

    CellStyle newStyle = wb.createCellStyle();
    newStyle.setAlignment(convertHorizontalAlign(style.getHorizontalAlignment()));
    newStyle.setVerticalAlignment(convertVerticalAlign(style.getVerticalAlignment()));

    Border border = style.getBorders(Border.LINE_BOTTOM);
    if (border != null) {
        newStyle.setBorderBottom(getBorder(border));
        newStyle.setBottomBorderColor(colorToIndex(wb, border.getColor()));
    }//from   w w  w  .java  2  s.c o m
    border = style.getBorders(Border.LINE_TOP);
    if (border != null) {
        newStyle.setBorderTop(getBorder(border));
        newStyle.setTopBorderColor(colorToIndex(wb, border.getColor()));
    }
    border = style.getBorders(Border.LINE_LEFT);
    if (border != null) {
        newStyle.setBorderLeft(getBorder(border));
        newStyle.setLeftBorderColor(colorToIndex(wb, border.getColor()));
    }
    border = style.getBorders(Border.LINE_RIGHT);
    if (border != null) {
        newStyle.setBorderRight(getBorder(border));
        newStyle.setRightBorderColor(colorToIndex(wb, border.getColor()));
    }

    Font font = wb.createFont();
    font.setFontName(style.getFamily());
    if (style.isBold()) {
        font.setBold(true);
    }
    font.setItalic(style.isItalic());
    if (style.isUnderline()) {
        font.setUnderline(Font.U_SINGLE);
    }
    if (style.isStrikethrough()) {
        font.setStrikeout(true);
    }
    font.setFontHeightInPoints((short) style.getSize());
    if (style.getForegroundColor() != null && !style.getForegroundColor().equals(Color.black)) {
        font.setColor(colorToIndex(wb, style.getForegroundColor()));
    }

    newStyle.setFont(font);

    if (style.getBackground() != null && !style.getBackground().equals(Color.white)) {
        short colorIndex = colorToIndex(wb, style.getBackground());
        newStyle.setFillForegroundColor(colorIndex);
        newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    }

    if (style.getAngle() != 0) {
        int angle = style.getAngle();
        if (angle > 90 && angle <= 180) {
            angle = 90;
        } else if (angle > 180 && angle <= 270) {
            angle = -90;
        } else if (angle > 270) {
            angle = -(360 - angle);
        }
        newStyle.setRotation((short) angle);
    }

    newStyle.setWrapText(style.isWrapLine());

    return newStyle;
}

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

License:Apache License

protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) {

    XSSFCellStyle newStyle = (XSSFCellStyle) wb.createCellStyle();
    newStyle.setAlignment(convertHorizontalAlign(style.getHorizontalAlignment()));
    newStyle.setVerticalAlignment(convertVerticalAlign(style.getVerticalAlignment()));

    Border border = style.getBorders(Border.LINE_BOTTOM);
    if (border != null) {
        newStyle.setBorderBottom(getBorder(border));
        newStyle.setBottomBorderColor(new XSSFColor(border.getColor()));
    }//from www .jav a 2 s  .co  m
    border = style.getBorders(Border.LINE_TOP);
    if (border != null) {
        newStyle.setBorderTop(getBorder(border));
        newStyle.setTopBorderColor(new XSSFColor(border.getColor()));
    }
    border = style.getBorders(Border.LINE_LEFT);
    if (border != null) {
        newStyle.setBorderLeft(getBorder(border));
        newStyle.setLeftBorderColor(new XSSFColor(border.getColor()));
    }
    border = style.getBorders(Border.LINE_RIGHT);
    if (border != null) {
        newStyle.setBorderRight(getBorder(border));
        newStyle.setRightBorderColor(new XSSFColor(border.getColor()));
    }

    Font font = wb.createFont();
    font.setFontName(style.getFamily());
    if (style.isBold()) {
        font.setBold(true);
    }
    font.setItalic(style.isItalic());
    if (style.isUnderline()) {
        font.setUnderline(Font.U_SINGLE);
    }
    if (style.isStrikethrough()) {
        font.setStrikeout(true);
    }
    font.setFontHeightInPoints((short) style.getSize());
    if (style.getForegroundColor() != null && !style.getForegroundColor().equals(Color.black)) {
        font.setColor(colorToIndex(wb, style.getForegroundColor()));
    }

    newStyle.setFont(font);

    if (style.getBackground() != null && !style.getBackground().equals(Color.white)) {
        newStyle.setFillForegroundColor(new XSSFColor(style.getBackground()));
        newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    }

    if (style.getAngle() != 0) {
        int angle = style.getAngle();
        if (angle > 90 && angle <= 180) {
            angle = 90;
        } else if (angle > 180 && angle <= 270) {
            angle = -90;
        } else if (angle > 270) {
            angle = -(360 - angle);
        }
        newStyle.setRotation((short) angle);
    }

    newStyle.setWrapText(style.isWrapLine());

    return newStyle;
}