Example usage for org.apache.poi.ss.usermodel Workbook createFont

List of usage examples for org.apache.poi.ss.usermodel Workbook createFont

Introduction

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

Prototype

Font createFont();

Source Link

Document

Create a new Font and add it to the workbook's font table

Usage

From source file:opn.greenwebs.HyperlinkExample.java

public static void main(String[] args) throws Exception {
    Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
    CreationHelper createHelper = wb.getCreationHelper();

    //cell style for hyperlinks
    //by default hyperlinks are blue and underlined
    CellStyle hlink_style = wb.createCellStyle();
    Font hlink_font = wb.createFont();
    hlink_font.setUnderline(Font.U_SINGLE);
    hlink_font.setColor(IndexedColors.BLUE.getIndex());
    hlink_style.setFont(hlink_font);/*from w  w  w .j  a  v  a2s.c  o  m*/

    Cell cell;
    Sheet sheet = wb.createSheet("Hyperlinks");
    //URL
    cell = sheet.createRow(0).createCell((short) 0);
    cell.setCellValue("URL Link");

    Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
    link.setAddress("http://poi.apache.org/");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //link to a file in the current directory
    cell = sheet.createRow(1).createCell((short) 0);
    cell.setCellValue("File Link");
    link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
    link.setAddress("link1.xls");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //e-mail link
    cell = sheet.createRow(2).createCell((short) 0);
    cell.setCellValue("Email Link");
    link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL);
    //note, if subject contains white spaces, make sure they are url-encoded
    link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //link to a place in this workbook

    //create a target sheet and cell
    Sheet sheet2 = wb.createSheet("Target Sheet");
    sheet2.createRow(0).createCell((short) 0).setCellValue("Target Cell");

    cell = sheet.createRow(3).createCell((short) 0);
    cell.setCellValue("Worksheet Link");
    Hyperlink link2 = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
    link2.setAddress("'Target Sheet'!A1");
    cell.setHyperlink(link2);
    cell.setCellStyle(hlink_style);

    FileOutputStream out = new FileOutputStream("hyperinks.xlsx");
    wb.write(out);
    out.close();

}

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.SpreadSheetFormatOptions.java

License:Open Source License

public static Font createCommentFont(Workbook workbook, cfStructData _struct) throws Exception {
    Font font = workbook.createFont();

    if (_struct.containsKey("bold")) {
        if (_struct.getData("bold").getBoolean())
            font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        else//  w w w .j a v a 2s .  co m
            font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    }

    if (_struct.containsKey("color")) {
        String v = _struct.getData("color").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'color' (" + v + ")");
        } else
            font.setColor(s);
    }

    if (_struct.containsKey("font")) {
        font.setFontName(_struct.getData("font").getString());
    }

    if (_struct.containsKey("italic")) {
        font.setItalic(_struct.getData("italic").getBoolean());
    }

    if (_struct.containsKey("strikeout")) {
        font.setStrikeout(_struct.getData("strikeout").getBoolean());
    }

    if (_struct.containsKey("underline")) {
        font.setUnderline((byte) _struct.getData("underline").getInt());
    }

    if (_struct.containsKey("size")) {
        font.setFontHeightInPoints((short) _struct.getData("size").getInt());
    }

    return font;
}

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.SpreadSheetFormatOptions.java

License:Open Source License

public static CellStyle createCellStyle(Workbook workbook, cfStructData _struct) throws Exception {
    CellStyle style = workbook.createCellStyle();

    if (_struct.containsKey("alignment")) {
        String v = _struct.getData("alignment").getString();
        Short s = lookup_alignment.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'alignment' (" + v + ")");
        } else//from   ww w  . j  a v  a 2s  . c om
            style.setAlignment(s);
    }

    if (_struct.containsKey("bottomborder")) {
        String v = _struct.getData("bottomborder").getString();
        Short s = lookup_border.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'bottomborder' (" + v + ")");
        } else
            style.setBorderBottom(s);
    }

    if (_struct.containsKey("topborder")) {
        String v = _struct.getData("topborder").getString();
        Short s = lookup_border.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'topborder' (" + v + ")");
        } else
            style.setBorderTop(s);
    }

    if (_struct.containsKey("leftborder")) {
        String v = _struct.getData("leftborder").getString();
        Short s = lookup_border.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'leftborder' (" + v + ")");
        } else
            style.setBorderLeft(s);
    }

    if (_struct.containsKey("rightborder")) {
        String v = _struct.getData("rightborder").getString();
        Short s = lookup_border.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'rightborder' (" + v + ")");
        } else
            style.setBorderRight(s);
    }

    if (_struct.containsKey("bottombordercolor")) {
        String v = _struct.getData("bottombordercolor").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'bottombordercolor' (" + v + ")");
        } else
            style.setBottomBorderColor(s);
    }

    if (_struct.containsKey("topbordercolor")) {
        String v = _struct.getData("topbordercolor").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'topbordercolor' (" + v + ")");
        } else
            style.setTopBorderColor(s);
    }

    if (_struct.containsKey("leftbordercolor")) {
        String v = _struct.getData("leftbordercolor").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'leftbordercolor' (" + v + ")");
        } else
            style.setLeftBorderColor(s);
    }

    if (_struct.containsKey("rightbordercolor")) {
        String v = _struct.getData("rightbordercolor").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'rightbordercolor' (" + v + ")");
        } else
            style.setRightBorderColor(s);
    }

    if (_struct.containsKey("fillpattern")) {
        String v = _struct.getData("fillpattern").getString();
        Short s = lookup_fillpatten.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'fillpattern' (" + v + ")");
        } else
            style.setFillPattern(s);
    }

    if (_struct.containsKey("fgcolor")) {
        String v = _struct.getData("fgcolor").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'fgcolor' (" + v + ")");
        } else
            style.setFillForegroundColor(s);
    }

    if (_struct.containsKey("bgcolor")) {
        String v = _struct.getData("bgcolor").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'bgcolor' (" + v + ")");
        } else
            style.setFillBackgroundColor(s);
    }

    if (_struct.containsKey("textwrap")) {
        Boolean b = _struct.getData("textwrap").getBoolean();
        style.setWrapText(b);
    }

    if (_struct.containsKey("hidden")) {
        Boolean b = _struct.getData("hidden").getBoolean();
        style.setHidden(b);
    }

    if (_struct.containsKey("locked")) {
        Boolean b = _struct.getData("locked").getBoolean();
        style.setLocked(b);
    }

    if (_struct.containsKey("indent")) {
        style.setIndention((short) _struct.getData("indent").getInt());
    }

    if (_struct.containsKey("rotation")) {
        style.setRotation((short) _struct.getData("rotation").getInt());
    }

    if (_struct.containsKey("dateformat")) {
        style.setDataFormat(workbook.createDataFormat().getFormat(_struct.getData("dateformat").getString()));
    }

    // Manage the fonts
    Font f = workbook.createFont();

    if (_struct.containsKey("strikeout")) {
        f.setStrikeout(true);
    }

    if (_struct.containsKey("bold")) {
        Boolean b = _struct.getData("bold").getBoolean();
        f.setBoldweight(b ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL);
    }

    if (_struct.containsKey("underline")) {
        String v = _struct.getData("underline").getString();
        Byte b = lookup_underline.get(v);
        if (b == null) {
            throw new Exception("invalid parameter for 'underline' (" + v + ")");
        } else
            f.setUnderline(b);
    }

    if (_struct.containsKey("color")) {
        String v = _struct.getData("color").getString();
        Short s = lookup_colors.get(v);
        if (s == null) {
            throw new Exception("invalid parameter for 'color' (" + v + ")");
        } else
            f.setColor(s);
    }

    if (_struct.containsKey("fontsize")) {
        int s = _struct.getData("fontsize").getInt();
        f.setFontHeightInPoints((short) s);
    }

    if (_struct.containsKey("font")) {
        f.setFontName(_struct.getData("font").getString());
    }

    style.setFont(f);

    return style;
}

From source file:org.alfresco.repo.web.scripts.DeclarativeSpreadsheetWebScript.java

License:Open Source License

/**
 * Generates the spreadsheet, based on the properties in the header
 *  and a callback for the body./*www  . j  a  v  a 2 s  .  c  om*/
 */
public void generateSpreadsheet(Object resource, String format, WebScriptRequest req, Status status,
        Map<String, Object> model) throws IOException {
    Pattern qnameMunger = Pattern.compile("([A-Z][a-z]+)([A-Z].*)");
    String delimiterParam = req.getParameter(PARAM_REQ_DELIMITER);
    CSVStrategy reqCSVstrategy = null;
    if (delimiterParam != null && !delimiterParam.isEmpty()) {
        reqCSVstrategy = new CSVStrategy(delimiterParam.charAt(0), '"', CSVStrategy.COMMENTS_DISABLED);
    }
    // Build up the details of the header
    List<Pair<QName, Boolean>> propertyDetails = buildPropertiesForHeader(resource, format, req);
    String[] headings = new String[propertyDetails.size()];
    String[] descriptions = new String[propertyDetails.size()];
    boolean[] required = new boolean[propertyDetails.size()];
    for (int i = 0; i < headings.length; i++) {
        Pair<QName, Boolean> property = propertyDetails.get(i);
        if (property == null || property.getFirst() == null) {
            headings[i] = "";
            required[i] = false;
        } else {
            QName column = property.getFirst();
            required[i] = property.getSecond();

            // Ask the dictionary service nicely for the details
            PropertyDefinition pd = dictionaryService.getProperty(column);
            if (pd != null && pd.getTitle(dictionaryService) != null) {
                // Use the friendly titles, which may even be localised!
                headings[i] = pd.getTitle(dictionaryService);
                descriptions[i] = pd.getDescription(dictionaryService);
            } else {
                // Nothing friendly found, try to munge the raw qname into
                //  something we can show to a user...
                String raw = column.getLocalName();
                raw = raw.substring(0, 1).toUpperCase() + raw.substring(1);

                Matcher m = qnameMunger.matcher(raw);
                if (m.matches()) {
                    headings[i] = m.group(1) + " " + m.group(2);
                } else {
                    headings[i] = raw;
                }
            }
        }
    }

    // Build a list of just the properties
    List<QName> properties = new ArrayList<QName>(propertyDetails.size());
    for (Pair<QName, Boolean> p : propertyDetails) {
        QName qn = null;
        if (p != null) {
            qn = p.getFirst();
        }
        properties.add(qn);
    }

    // Output
    if ("csv".equals(format)) {
        StringWriter sw = new StringWriter();
        CSVPrinter csv = new CSVPrinter(sw, reqCSVstrategy != null ? reqCSVstrategy : getCsvStrategy());
        csv.println(headings);

        populateBody(resource, csv, properties);

        model.put(MODEL_CSV, sw.toString());
    } else {
        Workbook wb;
        if ("xlsx".equals(format)) {
            wb = new XSSFWorkbook();
            // TODO Properties
        } else {
            wb = new HSSFWorkbook();
            // TODO Properties
        }

        // Add our header row
        Sheet sheet = wb.createSheet("Export");
        Row hr = sheet.createRow(0);
        sheet.createFreezePane(0, 1);

        Font fb = wb.createFont();
        fb.setBoldweight(Font.BOLDWEIGHT_BOLD);
        Font fi = wb.createFont();
        fi.setBoldweight(Font.BOLDWEIGHT_BOLD);
        fi.setItalic(true);

        CellStyle csReq = wb.createCellStyle();
        csReq.setFont(fb);
        CellStyle csOpt = wb.createCellStyle();
        csOpt.setFont(fi);

        // Populate the header
        Drawing draw = null;
        for (int i = 0; i < headings.length; i++) {
            Cell c = hr.createCell(i);
            c.setCellValue(headings[i]);

            if (required[i]) {
                c.setCellStyle(csReq);
            } else {
                c.setCellStyle(csOpt);
            }

            if (headings[i].length() == 0) {
                sheet.setColumnWidth(i, 3 * 250);
            } else {
                sheet.setColumnWidth(i, 18 * 250);
            }

            if (descriptions[i] != null && descriptions[i].length() > 0) {
                // Add a description for it too
                if (draw == null) {
                    draw = sheet.createDrawingPatriarch();
                }
                ClientAnchor ca = wb.getCreationHelper().createClientAnchor();
                ca.setCol1(c.getColumnIndex());
                ca.setCol2(c.getColumnIndex() + 1);
                ca.setRow1(hr.getRowNum());
                ca.setRow2(hr.getRowNum() + 2);

                Comment cmt = draw.createCellComment(ca);
                cmt.setAuthor("");
                cmt.setString(wb.getCreationHelper().createRichTextString(descriptions[i]));
                cmt.setVisible(false);
                c.setCellComment(cmt);
            }
        }

        // Have the contents populated
        populateBody(resource, wb, sheet, properties);

        // Save it for the template
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        wb.write(baos);
        model.put(MODEL_EXCEL, baos.toByteArray());
    }
}

From source file:org.apache.metamodel.excel.ExcelUpdateCallback.java

License:Apache License

public Font createFont() {
    Workbook workbook = getWorkbook(true);
    return workbook.createFont();
}

From source file:org.dashbuilder.dataset.backend.DataSetBackendServicesImpl.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;/*from   ww  w .  j  a v  a  2s . com*/

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(titleFont);
    style.setWrapText(false);
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
    styles.put("header", style);

    Font cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 10);
    cellFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3)));
    styles.put("integer_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4)));
    styles.put("decimal_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
    styles.put("text_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat()
            .getFormat(DateFormatConverter.convert(Locale.getDefault(), dateFormatPattern)));
    styles.put("date_cell", style);
    return styles;
}

From source file:org.dashbuilder.dataset.service.DataSetExportServicesImpl.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<>();
    CellStyle style;/*from w w w . ja v a  2  s .c  o m*/

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBold(true);
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFont(titleFont);
    style.setWrapText(false);
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
    styles.put("header", style);

    Font cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 10);
    cellFont.setBold(true);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setVerticalAlignment(VerticalAlignment.BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3)));
    styles.put("integer_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setVerticalAlignment(VerticalAlignment.BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4)));
    styles.put("decimal_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
    styles.put(TEXT_CELL, style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat()
            .getFormat(DateFormatConverter.convert(Locale.getDefault(), dateFormatPattern)));
    styles.put("date_cell", style);
    return styles;
}

From source file:org.eclipse.sw360.exporter.ExcelExporter.java

License:Open Source License

/**
 * Create header style, same has cell style but with bold font
 *///from  w  ww  .  j a  v a 2  s. c om
private static CellStyle createHeaderStyle(Workbook workbook) {
    CellStyle headerCellStyle = createCellStyle(workbook);
    Font font = workbook.createFont();
    font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    headerCellStyle.setFont(font);
    return headerCellStyle;
}

From source file:org.exist.xquery.corenlp.Tokenize.java

License:Open Source License

private void createXSLXSpreadsheet(List<List<CoreLabel>> sentences, List<CoreLabel> tokens) {
    Workbook workbook = null;
    if (outputFormat == OutDocType.XSLX) {
        workbook = new SXSSFWorkbook();
    } else {/*from w ww  .ja v  a  2  s.c  om*/
        workbook = new HSSFWorkbook();
    }
    CreationHelper creationHelper = workbook.getCreationHelper();
    org.apache.poi.ss.usermodel.Sheet sheet = workbook.createSheet();

    Font boldFont = workbook.createFont();
    boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

    // Header
    CellStyle headerStyle = workbook.createCellStyle();
    headerStyle.setFont(boldFont);
    int lineIndex = 0;
    for (List<CoreLabel> sentence : sentences) {
        for (CoreLabel token : sentence) {
            String value = token.get(CoreAnnotations.OriginalTextAnnotation.class);
            Row row = sheet.createRow(lineIndex);
            row.createCell(0).setCellValue(creationHelper.createRichTextString(value));
            row.createCell(1).setCellValue(creationHelper.createRichTextString(backgroundSymbol));
            lineIndex++;
        }
        Row row = sheet.createRow(lineIndex);
        row.createCell(0).setCellValue(creationHelper.createRichTextString(""));
        row.createCell(1).setCellValue(creationHelper.createRichTextString(""));
        lineIndex++;
    }

    try (OutputStream os = Files.newOutputStream(tempOutFile)) {
        workbook.write(os);
    } catch (FileNotFoundException fe) {
        LOG.error(fe);
    } catch (IOException ioe) {
        LOG.error(ioe);
    } finally {
        if (workbook != null) {
            if (workbook instanceof SXSSFWorkbook) {
                ((SXSSFWorkbook) workbook).dispose();
            } else {
                workbook = null;
            }
        }
    }
}

From source file:org.forzaframework.util.ExcelUtils.java

License:Apache License

static public void modelToExcelSheet(Workbook wb, String sheetName, List<Map<String, Object>> headers,
        List<Map<String, Object>> data, List<Map<String, Object>> footers, Integer freezePane,
        Boolean defaultFormat, Boolean createNewSheet, Integer indexSheet, Integer startInRow,
        Boolean printHeader, Boolean autoSizeColumns) {
    Sheet sheet = getSheet(wb, sheetName, createNewSheet, indexSheet);
    CellStyle headerCellStyle = getDefaultHeaderCellStyle(wb, defaultFormat);
    CellStyle titlesCellStyle = null;//from   ww  w.ja  v a 2 s.  c o m
    if (defaultFormat != null && defaultFormat) {
        titlesCellStyle = wb.createCellStyle();
        //Creamos el tipo de fuente
        Font titleFont = wb.createFont();
        //            headerFont.setFontName(HSSFFont.FONT_ARIAL);
        titleFont.setBold(Boolean.TRUE);
        titleFont.setColor(Font.COLOR_NORMAL);
        titleFont.setFontHeightInPoints((short) 8);
        titlesCellStyle.setFont(titleFont);
    }

    Integer col = 0;
    Integer row = 0;
    if (startInRow != null) {
        row = startInRow;
    }
    Map<Integer, Integer> columnWidthMap = new HashMap<Integer, Integer>();
    //Indice de la fila donde empieza los encabezados de titulo de cada columna
    Integer principalHeaderIndex = headers.size() - 1;
    if (printHeader != null && printHeader) {
        //Armamos el encabezado
        for (Map<String, Object> header : headers) {
            for (Map.Entry<String, Object> entry : header.entrySet()) {
                Cell cell = getCell(sheet, row, col);
                if (defaultFormat != null && defaultFormat) {
                    if (principalHeaderIndex.equals(row)) {
                        //Colocamos el formato de la celda
                        cell.setCellStyle(headerCellStyle);
                    } else {
                        cell.setCellStyle(titlesCellStyle);
                    }
                }
                setValue(cell, entry.getValue());
                //Especificamos el ancho que tendra la columna
                if (autoSizeColumns != null && autoSizeColumns) {
                    columnWidthMap.put(col, entry.getValue().toString().length());
                }
                col++;
            }
            row++;
            col = 0;
        }
        //Ponemos la altura del encabezado
        setRowHeight(sheet, row - 1, (short) 420);
    }

    CellStyle detailCellStyle = getDefaultDetailCellStyle(wb, defaultFormat);

    Map<String, Object> principalHeader = headers.get(principalHeaderIndex);
    // datos
    for (Map<String, Object> map : data) {
        for (Map.Entry<String, Object> entry : principalHeader.entrySet()) {
            Object value = map.get(entry.getKey());
            buildCellAndCalculateColumnWidth(sheet, value, col, row, detailCellStyle, columnWidthMap,
                    autoSizeColumns);
            col++;
        }
        col = 0;
        row++;
    }
    CellStyle totalCellStyle = null;
    if (defaultFormat != null && defaultFormat) {
        //Armamos el formato los totales
        totalCellStyle = wb.createCellStyle();
        Font totalFont = wb.createFont();
        totalFont.setBold(Boolean.TRUE);
        totalFont.setColor(Font.COLOR_NORMAL);
        totalFont.setFontHeightInPoints((short) 8);
        totalCellStyle.setFont(totalFont);
    }

    if (footers != null) {
        for (Map<String, Object> footer : footers) {
            for (Map.Entry<String, Object> entry : principalHeader.entrySet()) {
                Cell cell = getCell(sheet, row, col++);
                if (totalCellStyle != null) {
                    //Colocamos el formato de la celda
                    cell.setCellStyle(totalCellStyle);
                }

                Object object = footer.get(entry.getKey());
                if (object != null) {
                    setValue(cell, object);
                } else {
                    setText(cell, "");
                }
            }
        }
    }

    if (autoSizeColumns != null && autoSizeColumns) {
        setColumnsWidth(sheet, columnWidthMap, principalHeader.size());
    }

    if (freezePane != null && freezePane > 0) {
        //Colocamos la columna estatica y las filas del encabezado estaticas
        sheet.createFreezePane(freezePane, headers.size());
    }
}