Example usage for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.

Prototype

short BOLDWEIGHT_BOLD

To view the source code for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.

Click Source Link

Document

Bold boldness (bold)

Usage

From source file:com.plugin.excel.util.ExcelFileHelper.java

License:Apache License

private static void formatCell(Workbook workbook, Cell cell, ExcelCell excell,
        Map<IndexedColors, CellStyle> s_cellStyle, Font font, Font invisibleFont) {

    if (excell.getFormat() != null) {

        ExcelFormat format = excell.getFormat();

        CellStyle style = s_cellStyle.get(format.getBackgroundColor());

        if (format.isDate()) {
            // for date create a new style
            style = getDateStyle("date", cell.getSheet(), font);
            XSSFCreationHelper createHelper = (XSSFCreationHelper) cell.getSheet().getWorkbook()
                    .getCreationHelper();
            style.setDataFormat(createHelper.createDataFormat().getFormat("MMMM dd, yyyy"));
            font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
            font.setBold(false);//from  www .  j  a  va  2 s  .c  o m
            font.setFontHeightInPoints((short) 12);
            style.setFont(font);
            cell.setCellValue(new Date());
        }

        if (style == null) {
            style = workbook.createCellStyle();
            s_cellStyle.put(format.getBackgroundColor(), style);
        }

        if (format.getAlignment() > 0) {
            style.setAlignment(format.getAlignment());
        }
        if (format.getBackgroundColor() != null && !IndexedColors.WHITE.equals(format.getBackgroundColor())) {
            style.setFillForegroundColor(format.getBackgroundColor().getIndex());
            style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        }
        if (format.getTextColor() != null) {
            font.setColor(format.getTextColor().getIndex());
            style.setFont(font);
        }
        if (format.isBold()) {
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        if (format.getFontHeight() > 0) {
            font.setFontHeightInPoints(format.getFontHeight());
        }
        if (format.isWrapText()) {
            style.setWrapText(true);
        }
        style.setFont(font);
        if (format.isHideText()) {
            invisibleFont.setColor(IndexedColors.WHITE.getIndex());
            style.setFont(invisibleFont);
        }
        cell.setCellStyle(style);

    } else {
        // Let's set default formatting for free text cell
        IndexedColors defaultStyle = IndexedColors.AUTOMATIC; // we are using this index
        CellStyle style = s_cellStyle.get(defaultStyle);
        if (style == null) {
            style = workbook.createCellStyle();
            s_cellStyle.put(defaultStyle, style);
        }
        style.setWrapText(true);
        cell.setCellStyle(style);

    }

}

From source file:com.project.jsica.cdi.ReporteBean.java

public void reporte2(List<ReportePermisoBean> reporte) {
    LOG.info("TAMAO reporte: " + reporte.size());
    FacesContext fc = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

    HSSFWorkbook libro = new HSSFWorkbook();

    HSSFFont fuente = libro.createFont();
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle estiloCeldaCabecera = libro.createCellStyle();
    estiloCeldaCabecera.setFont(fuente);
    estiloCeldaCabecera.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    DataFormat format = libro.createDataFormat();

    HSSFCellStyle style = libro.createCellStyle();
    style.setDataFormat(format.getFormat("hh:mm:ss"));

    HSSFCellStyle fechas = libro.createCellStyle();
    fechas.setDataFormat(format.getFormat("dd.MM.yyyy"));

    HSSFSheet hoja = libro.createSheet("hoja 1");

    //CREAR LAS CABECERAS
    String[] cabeceras = { "CODIGO", "NOMBRE", "HORA INICIO", "HORA FIN", "HORAS", "MINUTOS", "FECHA",
            "MOTIVO" };

    HSSFRow filaCabecera = hoja.createRow(0);

    for (int x = 0; x < cabeceras.length; x++) {
        HSSFCell cabecera = filaCabecera.createCell(x);
        cabecera.setCellValue(cabeceras[x]);
        cabecera.setCellStyle(estiloCeldaCabecera);
    }/*ww w .j ava 2 s .  c  om*/
    //FIN DE CABECERAS
    for (int i = 0; i < reporte.size(); i++) {

        HSSFRow fila = hoja.createRow(i + 1);

        HSSFCell columna1 = fila.createCell(0);
        columna1.setCellValue(reporte.get(i).getCodigo());

        HSSFCell columna2 = fila.createCell(1);
        columna2.setCellValue(reporte.get(i).getNombre());

        HSSFCell columna3 = fila.createCell(2);
        columna3.setCellValue(reporte.get(i).getHoraInicio());
        columna3.setCellStyle(style);

        HSSFCell columna4 = fila.createCell(3);
        columna4.setCellValue(reporte.get(i).getHoraFin());
        columna4.setCellStyle(style);

        HSSFCell columna5 = fila.createCell(4);
        columna5.setCellValue(reporte.get(i).getHoras());

        HSSFCell columna6 = fila.createCell(5);
        columna6.setCellValue(reporte.get(i).getMinutos());

        HSSFCell columna7 = fila.createCell(6);
        columna7.setCellValue(reporte.get(i).getFechaReal());
        columna7.setCellStyle(fechas);

        HSSFCell columna8 = fila.createCell(7);
        columna8.setCellValue(reporte.get(i).getMotivo());
    }

    try {

        OutputStream output = response.getOutputStream();

        libro.write(output);
        output.close();

        fc.responseComplete();

    } catch (IOException ex) {
        LOG.info("ERROR: " + ex);
    }
}

From source file:com.project.jsica.cdi.ReporteBean.java

public void reporte3() {
    if (nuevoReporte) {
        LOG.info("OPCION: " + opcionReporte);
        String nombreReporte = "";
        int filas = 0;
        if (opcionReporte == 2) {
            reporte = registroAsistenciaController.buscarXArea(areaSeleccionada, desde, hasta);
            LOG.info("TAMAO reporte: " + reporte.size());
            nombreReporte = "Reporte de asistencia por area";
            filas = 1;//from   w  w  w . j  a  v a2  s . c  o m
        } else if (opcionReporte == 1) {
            reporte = registroAsistenciaController.buscarXEmpleado(empleado, desde, hasta);
            LOG.info("TAMAO reporte: " + reporte.size());
            nombreReporte = "Reporte de asistencia por empleado";
            filas = 0;
        }

        FacesContext fc = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

        response.reset();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=" + nombreReporte + ".xls");

        HSSFWorkbook libro = new HSSFWorkbook();

        HSSFFont fuente = libro.createFont();
        fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        HSSFCellStyle estiloCeldaCabecera = libro.createCellStyle();
        estiloCeldaCabecera.setFont(fuente);
        estiloCeldaCabecera.setAlignment(HSSFCellStyle.ALIGN_CENTER);

        DataFormat format = libro.createDataFormat();

        HSSFCellStyle style = libro.createCellStyle();
        style.setDataFormat(format.getFormat("hh:mm:ss"));

        HSSFCellStyle fechas = libro.createCellStyle();
        fechas.setDataFormat(format.getFormat("dd.MM.yyyy"));

        HSSFSheet hoja = libro.createSheet("Reporte de Asistencias");

        //CREAR LAS CABECERAS
        String[] cabeceras = { "CODIGO", "APELLIDOS Y NOMBRES", "FECHA", "TIPO", "HORA DE INGRESO",
                "HORA DE SALIDA", "MARCACION DE ENTRADA", "MARCACION DE SALIDA", "TARDANZA(Minutos)",
                "SALIDA REFRIGERIO", "ENTRADA REFRIGERIO", "MARCACION SALIDA R", "MARCACION DE ENTRADA R",
                "TARDANZA(refrigerio)", "TARDANZA TOTAL" };

        if (filas == 1) {
            HSSFRow filaArea = hoja.createRow(0);
            HSSFCell Area = filaArea.createCell(0);
            Area.setCellValue("AREA");
            Area.setCellStyle(estiloCeldaCabecera);

            HSSFCell nombre = filaArea.createCell(1);
            nombre.setCellValue(areaSeleccionada.getNombre() + "");
        }

        HSSFRow filaCabecera = hoja.createRow(filas);

        for (int x = 0; x < cabeceras.length; x++) {
            HSSFCell cabecera = filaCabecera.createCell(x);
            cabecera.setCellValue(cabeceras[x]);
            cabecera.setCellStyle(estiloCeldaCabecera);
        }
        //FIN DE CABECERAS
        for (int i = filas; i < reporte.size(); i++) {

            HSSFRow fila = hoja.createRow(i + 1);

            HSSFCell columna1 = fila.createCell(0);
            columna1.setCellValue(reporte.get(i).getEmpleado().getCodigo());

            HSSFCell columna2 = fila.createCell(1);
            columna2.setCellValue(reporte.get(i).getEmpleado().getNombreCompleto());

            HSSFCell columna3 = fila.createCell(2);
            columna3.setCellValue(reporte.get(i).getFecha());
            columna3.setCellStyle(fechas);

            HSSFCell columna4 = fila.createCell(3);
            columna4.setCellValue(reporte.get(i).getTipo() + "");

            HSSFCell columna5 = fila.createCell(4);
            columna5.setCellValue(reporte.get(i).getHoraEntrada());
            columna5.setCellStyle(style);

            HSSFCell columna6 = fila.createCell(5);
            columna6.setCellValue(reporte.get(i).getHoraSalida());
            columna6.setCellStyle(style);

            HSSFCell columna7 = fila.createCell(6);
            if (reporte.get(i).getMarcacionInicio() != null) {
                columna7.setCellValue(reporte.get(i).getMarcacionInicio());
                columna7.setCellStyle(style);
            } else {
                columna7.setCellValue("No marco.");
            }

            HSSFCell columna8 = fila.createCell(7);
            if (reporte.get(i).getMarcacionFin() != null) {
                columna8.setCellValue(reporte.get(i).getMarcacionFin());
                columna8.setCellStyle(style);
            } else {
                columna8.setCellValue("No marco.");
            }

            HSSFCell columna9 = fila.createCell(8);
            int minutos = (int) ((reporte.get(i).getMilisTardanzaTotal() / (1000 * 60)) % 60);
            columna9.setCellValue(minutos);

            HSSFCell columna10 = fila.createCell(9);
            columna10.setCellValue(reporte.get(i).getHoraSalidaRefrigerio());
            columna10.setCellStyle(style);

            HSSFCell columna11 = fila.createCell(10);
            columna11.setCellValue(reporte.get(i).getHoraEntradaRefrigerio());
            columna11.setCellStyle(style);

            HSSFCell columna12 = fila.createCell(11);
            if (reporte.get(i).getMarcacionInicioRefrigerio() != null) {
                columna12.setCellValue(reporte.get(i).getMarcacionInicioRefrigerio());
                columna12.setCellStyle(style);
            } else {
                columna12.setCellValue("No marco.");
            }

            HSSFCell columna13 = fila.createCell(12);
            if (reporte.get(i).getMarcacionFinRefrigerio() != null) {
                columna13.setCellValue(reporte.get(i).getMarcacionFinRefrigerio());
                columna13.setCellStyle(style);
            } else {
                columna13.setCellValue("No marco.");
            }

            HSSFCell columna14 = fila.createCell(13);
            columna14.setCellValue((int) ((reporte.get(i).getMilisTardanzaRefrigerio() / (1000 * 60)) % 60));

            HSSFCell columna15 = fila.createCell(14);
            columna15.setCellValue((int) ((reporte.get(i).getMilisTardanzaTotalFinal() / (1000 * 60)) % 60));

        }

        try {
            OutputStream output = response.getOutputStream();

            libro.write(output);
            output.close();

            fc.responseComplete();
        } catch (IOException ex) {
            LOG.info("ERROR: " + ex);
        }

        nuevoReporte = false;
    }

}

From source file:com.pureinfo.dolphin.export.impl.ExcelExporterImpl.java

License:Open Source License

/**
 * Returns the head style//  w  w  w .ja  v a 2s.  c o  m
 * 
 * @param _workbook
 *            excell work book
 * @return the head style
 */
protected HSSFCellStyle getHeaderStyle(HSSFWorkbook _workbook) {
    HSSFCellStyle headerStyle = _workbook.createCellStyle();
    headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    HSSFFont headFont = _workbook.createFont();
    headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerStyle.setFont(headFont);
    return headerStyle;
}

From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java

License:Open Source License

/**
 * Returns the date style in excel.// ww  w.  j a  va  2  s  .c  o  m
 * 
 * @param _workbook
 *            excell work book
 * @return the date style in excel.
 */
protected HSSFCellStyle getDateStyle(HSSFWorkbook _workbook) {
    HSSFCellStyle dateStyle = _workbook.createCellStyle();
    HSSFDataFormat fmt = _workbook.createDataFormat();
    dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("yy-mm"));
    HSSFFont font = _workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    dateStyle.setWrapText(true);
    dateStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    dateStyle.setFont(font);
    return dateStyle;
}

From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java

License:Open Source License

protected HSSFCellStyle getDoubleStyle(HSSFWorkbook _workbook) {
    HSSFCellStyle doubleStyle = _workbook.createCellStyle();
    HSSFFont font = _workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    doubleStyle.setWrapText(true);/*from ww w  .j  a v  a 2s .  c  om*/
    HSSFDataFormat fmt = _workbook.createDataFormat();
    doubleStyle.setDataFormat(fmt.getFormat("0.00"));
    doubleStyle.setFont(font);
    return doubleStyle;
}

From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java

License:Open Source License

/**
 * Returns the head style//  w w w.  j  a  v  a 2  s.c  om
 * 
 * @param _workbook
 *            excell work book
 * @return the head style
 */
protected HSSFCellStyle getHeaderStyle(HSSFWorkbook _workbook) {
    HSSFCellStyle headerStyle = _workbook.createCellStyle();
    headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    HSSFFont headFont = _workbook.createFont();
    headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerStyle.setFont(headFont);
    headerStyle.setWrapText(true);
    return headerStyle;
}

From source file:com.report.excel.ExcelToHtmlConverter.java

License:Apache License

void buildStyle_font(HSSFWorkbook workbook, StringBuilder style, HSSFFont font) {
    switch (font.getBoldweight()) {
    case HSSFFont.BOLDWEIGHT_BOLD:
        style.append("font-weight:bold;");
        break;/*from   w ww  .jav a2 s . c  om*/
    case HSSFFont.BOLDWEIGHT_NORMAL:
        // by default, not not increase HTML size
        // style.append( "font-weight: normal; " );
        break;
    }

    final HSSFColor fontColor = workbook.getCustomPalette().getColor(font.getColor());
    if (fontColor != null)
        style.append("color: " + ExcelToHtmlUtils.getColor(fontColor) + "; ");

    if (font.getFontHeightInPoints() != 0)
        style.append("font-size:" + font.getFontHeightInPoints() + "pt;");

    if (font.getItalic()) {
        style.append("font-style:italic;");
    }
}

From source file:com.sammyun.ExcelView.java

License:Open Source License

/**
 * ?Excel//w w w  .  ja va 2s . c o m
 * 
 * @param model ?
 * @param workbook workbook
 * @param request request
 * @param response response
 */
public void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Assert.notEmpty(properties);
    HSSFSheet sheet;
    if (StringUtils.isNotEmpty(sheetName)) {
        sheet = workbook.createSheet(sheetName);
    } else {
        sheet = workbook.createSheet();
    }
    int rowNumber = 0;
    if (titles != null && titles.length > 0) {
        HSSFRow header = sheet.createRow(rowNumber);
        header.setHeight((short) 400);
        for (int i = 0; i < properties.length; i++) {
            HSSFCell cell = header.createCell(i);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
            cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            HSSFFont font = workbook.createFont();
            font.setFontHeightInPoints((short) 11);
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            if (i == 0) {
                HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
                HSSFComment comment = patriarch
                        .createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 4, 4));
                comment.setString(new HSSFRichTextString("P" + "o" + "w" + "e" + "r" + "e" + "d" + " " + "B"
                        + "y" + " " + "M" + "o" + "S" + "ho" + "o" + "p"));
                cell.setCellComment(comment);
            }
            if (titles.length > i && titles[i] != null) {
                cell.setCellValue(titles[i]);
            } else {
                cell.setCellValue(properties[i]);
            }
            if (widths != null && widths.length > i && widths[i] != null) {
                sheet.setColumnWidth(i, widths[i]);
            } else {
                sheet.autoSizeColumn(i);
            }
        }
        rowNumber++;
    }
    if (data != null) {
        for (Object item : data) {
            HSSFRow row = sheet.createRow(rowNumber);
            for (int i = 0; i < properties.length; i++) {
                HSSFCell cell = row.createCell(i);
                if (converters != null && converters.length > i && converters[i] != null) {
                    Class<?> clazz = PropertyUtils.getPropertyType(item, properties[i]);
                    ConvertUtils.register(converters[i], clazz);
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                    ConvertUtils.deregister(clazz);
                    if (clazz.equals(Date.class)) {
                        DateConverter dateConverter = new DateConverter();
                        dateConverter.setPattern(DEFAULT_DATE_PATTERN);
                        ConvertUtils.register(dateConverter, Date.class);
                    }
                } else {
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                }
                if (rowNumber == 0 || rowNumber == 1) {
                    if (widths != null && widths.length > i && widths[i] != null) {
                        sheet.setColumnWidth(i, widths[i]);
                    } else {
                        sheet.autoSizeColumn(i);
                    }
                }
            }
            rowNumber++;
        }
    }
    if (contents != null && contents.length > 0) {
        rowNumber++;
        for (String content : contents) {
            HSSFRow row = sheet.createRow(rowNumber);
            HSSFCell cell = row.createCell(0);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            HSSFFont font = workbook.createFont();
            font.setColor(HSSFColor.GREY_50_PERCENT.index);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            cell.setCellValue(content);
            rowNumber++;
        }
    }
    response.setContentType("application/force-download");
    if (StringUtils.isNotEmpty(filename)) {
        response.setHeader("Content-disposition",
                "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
    } else {
        response.setHeader("Content-disposition", "attachment");
    }
}

From source file:com.sevenorcas.openstyle.app.service.spreadsheet.SpreadSheet.java

/**
 * Set a cell style as header/*from  ww  w.  ja v a  2  s  .  c o m*/
 * 
 * Thanks to http://www.experts-exchange.com/Programming/Languages/Java/Q_24242777.html
 * 
 * @param workbook
 * @param style id
 * @param rowStyle
 * @param column
 * @param wb
 * @return
 */
protected void setStyleHeader(HSSFWorkbook wb, HSSFCellStyle style, int styleId) { //EX1, int row, int column, SpreadsheetCell cell){
    HSSFFont font = wb.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    style.setFont(font);
    style.setLocked(true);
    style.setBottomBorderColor(HSSFColor.WHITE.index);
    style.setLeftBorderColor(HSSFColor.WHITE.index);
    style.setRightBorderColor(HSSFColor.WHITE.index);
    style.setTopBorderColor(HSSFColor.WHITE.index);
    style.setFillForegroundColor(getHeaderBGColorIndex());
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
}