Example usage for org.apache.poi.hssf.usermodel HSSFCellStyle setRotation

List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setRotation

Introduction

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

Prototype

@Override
public void setRotation(short rotation) 

Source Link

Document

set the degree of rotation for the text in the cell Note: HSSF uses values from -90 to 90 degrees, whereas XSSF uses values from 0 to 180 degrees.

Usage

From source file:com.develog.utils.report.engine.export.JRXlsExporter.java

License:Open Source License

/**
 *
 *///from  w  ww  .  j av a  2  s.  c  om
protected HSSFCellStyle getLoadedCellStyle(short mode, short backcolor, short horizontalAlignment,
        short verticalAlignment, short rotation, HSSFFont font) {
    HSSFCellStyle cellStyle = null;

    if (loadedCellStyles != null && loadedCellStyles.size() > 0) {
        HSSFCellStyle cs = null;
        for (int i = 0; i < loadedCellStyles.size(); i++) {
            cs = (HSSFCellStyle) loadedCellStyles.get(i);

            if (cs.getFillPattern() == mode && cs.getFillForegroundColor() == backcolor
                    && cs.getAlignment() == horizontalAlignment
                    && cs.getVerticalAlignment() == verticalAlignment && cs.getRotation() == rotation
                    && cs.getFontIndex() == font.getIndex()) {
                cellStyle = cs;
                break;
            }
        }
    }

    if (cellStyle == null) {
        cellStyle = workbook.createCellStyle();
        cellStyle.setFillForegroundColor(backcolor);
        cellStyle.setFillPattern(mode);
        cellStyle.setAlignment(horizontalAlignment);
        cellStyle.setVerticalAlignment(verticalAlignment);
        cellStyle.setRotation(rotation);
        cellStyle.setFont(font);
        cellStyle.setWrapText(true);

        loadedCellStyles.add(cellStyle);
    }

    return cellStyle;
}

From source file:com.eryansky.core.excelTools.ExcelUtils.java

License:Apache License

public static void copyCellStyle(HSSFWorkbook destwb, HSSFCellStyle dest, HSSFWorkbook srcwb,
        HSSFCellStyle src) {//  w w  w .  ja v a 2s. c o  m
    if (src == null || dest == null)
        return;
    dest.setAlignment(src.getAlignment());
    dest.setBorderBottom(src.getBorderBottom());
    dest.setBorderLeft(src.getBorderLeft());
    dest.setBorderRight(src.getBorderRight());
    dest.setBorderTop(src.getBorderTop());
    dest.setBottomBorderColor(findColor(src.getBottomBorderColor(), srcwb, destwb));
    dest.setDataFormat(
            destwb.createDataFormat().getFormat(srcwb.createDataFormat().getFormat(src.getDataFormat())));
    dest.setFillPattern(src.getFillPattern());
    dest.setFillForegroundColor(findColor(src.getFillForegroundColor(), srcwb, destwb));
    dest.setFillBackgroundColor(findColor(src.getFillBackgroundColor(), srcwb, destwb));
    dest.setHidden(src.getHidden());
    dest.setIndention(src.getIndention());
    dest.setLeftBorderColor(findColor(src.getLeftBorderColor(), srcwb, destwb));
    dest.setLocked(src.getLocked());
    dest.setRightBorderColor(findColor(src.getRightBorderColor(), srcwb, destwb));
    dest.setRotation(src.getRotation());
    dest.setTopBorderColor(findColor(src.getTopBorderColor(), srcwb, destwb));
    dest.setVerticalAlignment(src.getVerticalAlignment());
    dest.setWrapText(src.getWrapText());

    HSSFFont f = srcwb.getFontAt(src.getFontIndex());
    HSSFFont nf = findFont(f, srcwb, destwb);
    if (nf == null) {
        nf = destwb.createFont();
        nf.setBoldweight(f.getBoldweight());
        nf.setCharSet(f.getCharSet());
        nf.setColor(findColor(f.getColor(), srcwb, destwb));
        nf.setFontHeight(f.getFontHeight());
        nf.setFontHeightInPoints(f.getFontHeightInPoints());
        nf.setFontName(f.getFontName());
        nf.setItalic(f.getItalic());
        nf.setStrikeout(f.getStrikeout());
        nf.setTypeOffset(f.getTypeOffset());
        nf.setUnderline(f.getUnderline());
    }
    dest.setFont(nf);
}

From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java

License:Apache License

@Override
public void apply() {
    for (DataObject dataObject : data) {
        HSSFCell templateCell = dataObject.templateCell;
        HSSFCell resultCell = dataObject.resultCell;
        BandData bandData = dataObject.bandData;

        HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook();
        HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook();

        String templateCellValue = templateCell.getStringCellValue();

        Matcher matcher = pattern.matcher(templateCellValue);
        if (matcher.find()) {
            String paramName = matcher.group(1);
            String styleName = (String) bandData.getParameterValue(paramName);
            if (styleName == null)
                continue;

            HSSFCellStyle cellStyle = styleCache.getStyleByName(styleName);
            if (cellStyle == null)
                continue;

            HSSFCellStyle resultStyle = styleCache.getNamedCachedStyle(cellStyle);

            if (resultStyle == null) {
                HSSFCellStyle newStyle = resultWorkbook.createCellStyle();
                // color
                newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());
                newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());
                newStyle.setFillPattern(cellStyle.getFillPattern());

                // borders
                newStyle.setBorderLeft(cellStyle.getBorderLeft());
                newStyle.setBorderRight(cellStyle.getBorderRight());
                newStyle.setBorderTop(cellStyle.getBorderTop());
                newStyle.setBorderBottom(cellStyle.getBorderBottom());

                // border colors
                newStyle.setLeftBorderColor(cellStyle.getLeftBorderColor());
                newStyle.setRightBorderColor(cellStyle.getRightBorderColor());
                newStyle.setBottomBorderColor(cellStyle.getBottomBorderColor());
                newStyle.setTopBorderColor(cellStyle.getTopBorderColor());

                // alignment
                newStyle.setAlignment(cellStyle.getAlignment());
                newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment());
                // misc
                DataFormat dataFormat = resultWorkbook.getCreationHelper().createDataFormat();
                newStyle.setDataFormat(dataFormat.getFormat(cellStyle.getDataFormatString()));
                newStyle.setHidden(cellStyle.getHidden());
                newStyle.setLocked(cellStyle.getLocked());
                newStyle.setIndention(cellStyle.getIndention());
                newStyle.setRotation(cellStyle.getRotation());
                newStyle.setWrapText(cellStyle.getWrapText());
                // font
                HSSFFont cellFont = cellStyle.getFont(templateWorkbook);
                HSSFFont newFont = fontCache.getFontByTemplate(cellFont);

                if (newFont == null) {
                    newFont = resultWorkbook.createFont();

                    newFont.setFontName(cellFont.getFontName());
                    newFont.setItalic(cellFont.getItalic());
                    newFont.setStrikeout(cellFont.getStrikeout());
                    newFont.setTypeOffset(cellFont.getTypeOffset());
                    newFont.setBoldweight(cellFont.getBoldweight());
                    newFont.setCharSet(cellFont.getCharSet());
                    newFont.setColor(cellFont.getColor());
                    newFont.setUnderline(cellFont.getUnderline());
                    newFont.setFontHeight(cellFont.getFontHeight());
                    newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints());
                    fontCache.addCachedFont(cellFont, newFont);
                }/*from  w  w  w .  j a v  a 2s  . c om*/
                newStyle.setFont(newFont);

                resultStyle = newStyle;
                styleCache.addCachedNamedStyle(cellStyle, resultStyle);
            }

            fixNeighbourCellBorders(cellStyle, resultCell);

            resultCell.setCellStyle(resultStyle);

            Sheet sheet = resultCell.getSheet();
            for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
                CellRangeAddress mergedRegion = sheet.getMergedRegion(i);
                if (mergedRegion.isInRange(resultCell.getRowIndex(), resultCell.getColumnIndex())) {

                    int firstRow = mergedRegion.getFirstRow();
                    int lastRow = mergedRegion.getLastRow();
                    int firstCol = mergedRegion.getFirstColumn();
                    int lastCol = mergedRegion.getLastColumn();

                    for (int row = firstRow; row <= lastRow; row++)
                        for (int col = firstCol; col <= lastCol; col++)
                            sheet.getRow(row).getCell(col).setCellStyle(resultStyle);

                    // cell includes only in one merged region
                    break;
                }
            }
        }
    }
}

From source file:com.siteview.ecc.report.xls.JRXlsExporter.java

License:Open Source License

protected HSSFCellStyle getLoadedCellStyle(StyleInfo style) {
    HSSFCellStyle cellStyle = (HSSFCellStyle) loadedCellStyles.get(style);
    if (cellStyle == null) {
        cellStyle = workbook.createCellStyle();

        //         cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
        //         cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        cellStyle.setAlignment(style.horizontalAlignment);
        cellStyle.setVerticalAlignment(style.verticalAlignment);
        cellStyle.setRotation(style.rotation);
        cellStyle.setFont(style.font);/*from   w  w w  .ja v a2  s . c  o m*/
        cellStyle.setWrapText(true);

        if (style.hasDataFormat()) {
            cellStyle.setDataFormat(style.getDataFormat());
        }

        if (!isIgnoreCellBorder) {
            BoxStyle box = style.box;
            cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]);
            cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]);
            cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]);
            cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]);
            cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]);
            cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]);
            cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]);
            cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]);
        }

        loadedCellStyles.put(style, cellStyle);
    }
    return cellStyle;
}

From source file:net.sf.jasperreports.engine.export.JRXlsExporter.java

License:Open Source License

protected HSSFCellStyle getLoadedCellStyle(StyleInfo style) {
    HSSFCellStyle cellStyle = loadedCellStyles.get(style);
    if (cellStyle == null) {
        cellStyle = workbook.createCellStyle();

        cellStyle.setFillForegroundColor(style.backcolor);
        cellStyle.setFillPattern(style.mode);
        cellStyle.setAlignment(style.horizontalAlignment);
        cellStyle.setVerticalAlignment(style.verticalAlignment);
        cellStyle.setRotation(style.rotation);
        cellStyle.setFont(style.font);//from   w  w  w .ja  v  a2s.c  o  m
        cellStyle.setWrapText(style.lcWrapText);
        cellStyle.setLocked(style.lcCellLocked);
        cellStyle.setHidden(style.lcCellHidden);

        if (style.hasDataFormat()) {
            cellStyle.setDataFormat(style.getDataFormat());
        }

        boolean isIgnoreCellBorder = getCurrentItemConfiguration().isIgnoreCellBorder();
        if (!isIgnoreCellBorder) {
            BoxStyle box = style.box;
            cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]);
            cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]);
            cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]);
            cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]);
            cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]);
            cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]);
            cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]);
            cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]);
        }

        loadedCellStyles.put(style, cellStyle);
    }
    return cellStyle;
}

From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java

License:Open Source License

protected HSSFCellStyle getLoadedCellStyle(StyleInfo style) {
    HSSFCellStyle cellStyle = loadedCellStyles.get(style);
    if (cellStyle == null) {

        cellStyle = workbook.createCellStyle();
        cellStyle.setFillForegroundColor(style.backcolor);
        cellStyle.setFillPattern(style.mode);
        cellStyle.setAlignment(style.horizontalAlignment);
        cellStyle.setVerticalAlignment(style.verticalAlignment);
        cellStyle.setRotation(style.rotation);
        cellStyle.setFont(style.font);//from ww w.  java 2s  .  co  m
        cellStyle.setWrapText(style.lcWrapText);
        cellStyle.setLocked(style.lcCellLocked);
        cellStyle.setHidden(style.lcCellHidden);

        if (style.hasDataFormat()) {
            cellStyle.setDataFormat(style.getDataFormat());
        }

        if (!getCurrentItemConfiguration().isIgnoreCellBorder()) {
            BoxStyle box = style.box;
            cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]);
            cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]);
            cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]);
            cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]);
            cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]);
            cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]);
            cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]);
            cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]);
        }
        loadedCellStyles.put(style, cellStyle);
    }
    return cellStyle;
}

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copyCell(HSSFWorkbook workbook, HSSFCell destination, HSSFCell source) {

    // Copy cell content
    destination.setCellType(source.getCellType());
    switch (source.getCellType()) {
    case HSSFCell.CELL_TYPE_BOOLEAN:
        destination.setCellValue(source.getBooleanCellValue());
        break;//from w  ww .j  ava 2  s  . c  o m
    case HSSFCell.CELL_TYPE_FORMULA:
    case HSSFCell.CELL_TYPE_STRING:
        destination.setCellValue(source.getStringCellValue());
        break;
    case HSSFCell.CELL_TYPE_NUMERIC:
        destination.setCellValue(source.getNumericCellValue());
        break;
    }

    // Copy cell style
    HSSFCellStyle sourceCellStyle = source.getCellStyle();
    HSSFCellStyle destinationCellStyle = workbook.createCellStyle();
    destinationCellStyle.setAlignment(sourceCellStyle.getAlignment());
    destinationCellStyle.setBorderBottom(sourceCellStyle.getBorderBottom());
    destinationCellStyle.setBorderLeft(sourceCellStyle.getBorderLeft());
    destinationCellStyle.setBorderRight(sourceCellStyle.getBorderRight());
    destinationCellStyle.setBorderTop(sourceCellStyle.getBorderTop());
    destinationCellStyle.setBottomBorderColor(sourceCellStyle.getBottomBorderColor());
    destinationCellStyle.setDataFormat(sourceCellStyle.getDataFormat());
    destinationCellStyle.setFillBackgroundColor(sourceCellStyle.getFillForegroundColor());
    destinationCellStyle.setFillForegroundColor(sourceCellStyle.getFillForegroundColor());
    destinationCellStyle.setFillPattern(sourceCellStyle.getFillPattern());
    destinationCellStyle.setFont(workbook.getFontAt(sourceCellStyle.getFontIndex()));
    destinationCellStyle.setHidden(sourceCellStyle.getHidden());
    destinationCellStyle.setIndention(sourceCellStyle.getIndention());
    destinationCellStyle.setLeftBorderColor(sourceCellStyle.getLeftBorderColor());
    destinationCellStyle.setLocked(sourceCellStyle.getLocked());
    destinationCellStyle.setRightBorderColor(sourceCellStyle.getRightBorderColor());
    destinationCellStyle.setRotation(sourceCellStyle.getRotation());
    destinationCellStyle.setTopBorderColor(sourceCellStyle.getTopBorderColor());
    destinationCellStyle.setVerticalAlignment(sourceCellStyle.getVerticalAlignment());
    destinationCellStyle.setWrapText(sourceCellStyle.getWrapText());
    destination.setCellStyle(destinationCellStyle);
}

From source file:ro.nextreports.engine.exporter.XlsExporter.java

License:Apache License

private void renderCell(BandElement bandElement, String bandName, Object value, int gridRow, int sheetRow,
        int sheetColumn, int rowSpan, int colSpan, boolean image) {

    if (bandElement instanceof ReportBandElement) {
        colSpan = 1;/*from  w  ww .  j  a v  a2s. c  o m*/
    }
    HSSFCellStyle cellStyle = buildBandElementStyle(bandElement, value, gridRow, sheetColumn, colSpan);

    // if we have a subreport on the current grid row we have to take care of the sheetColumn
    if (ReportLayout.HEADER_BAND_NAME.equals(bandName) && (gridRow == prevSubreportFirstRow)
            && (prevSubreportLastColumn != -1)) {
        sheetColumn = prevSubreportLastColumn - prevSubreportFirstColumn - 1 + sheetColumn;
    }
    HSSFCell c = xlsRow.createCell(sheetColumn);

    if (image) {
        if ((value == null) || "".equals(value)) {
            c.setCellType(HSSFCell.CELL_TYPE_STRING);
            c.setCellValue(new HSSFRichTextString(IMAGE_NOT_FOUND));
        } else {
            try {
                ImageBandElement ibe = (ImageBandElement) bandElement;
                byte[] imageBytes = getImage((String) value, ibe.getWidth(), ibe.getHeight());
                HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) sheetColumn, sheetRow,
                        (short) (sheetColumn + colSpan), (sheetRow + rowSpan));
                int index = wb.addPicture(imageBytes, HSSFWorkbook.PICTURE_TYPE_JPEG);

                // image is created over the cells, so if it's height is bigger we set the row height
                short height = xlsRow.getHeight();
                int realImageHeight = getRealImageSize((String) value)[1];
                if (ibe.isScaled()) {
                    realImageHeight = ibe.getHeight();
                }
                short imageHeight = (short) (realImageHeight * POINTS_FOR_PIXEL / 2.5);
                if (imageHeight > height) {
                    xlsRow.setHeight(imageHeight);
                }

                HSSFPicture picture = patriarch.createPicture(anchor, index);
                picture.resize();
                anchor.setAnchorType(2);
            } catch (Exception ex) {
                c.setCellType(HSSFCell.CELL_TYPE_STRING);
                c.setCellValue(new HSSFRichTextString(IMAGE_NOT_LOADED));
            }
        }

        if (cellStyle != null) {
            c.setCellStyle(cellStyle);
        }

    } else {
        if (bandElement instanceof HyperlinkBandElement) {
            Hyperlink hyp = ((HyperlinkBandElement) bandElement).getHyperlink();
            HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
            link.setAddress(hyp.getUrl());
            c.setHyperlink(link);
            c.setCellValue(new HSSFRichTextString(hyp.getText()));
            c.setCellType(HSSFCell.CELL_TYPE_STRING);
        } else if (bandElement instanceof ReportBandElement) {
            Report report = ((ReportBandElement) bandElement).getReport();
            ExporterBean eb = null;
            try {
                eb = getSubreportExporterBean(report, true);
                XlsExporter subExporter = new XlsExporter(eb, cellStyle);
                subExporter.export();
                HSSFSheet subreportSheet = subExporter.getSubreportSheet();

                if (ReportLayout.HEADER_BAND_NAME.equals(bandName) && (gridRow == prevSubreportFirstRow)) {
                    // other subreports on the same header line after the first
                    sheetColumn = prevSubreportLastColumn;
                    sheetRow -= addedPageRows;
                    pageRow -= addedPageRows;
                    addedPageRows = 0;
                } else {
                    addedPageRows = subreportSheet.getLastRowNum();
                    pageRow += addedPageRows;
                    // if subreport is not on the first column we merge all cells in the columns before, between the rows subreport occupies
                    if (sheetColumn > 0) {
                        for (int i = 0; i <= sheetColumn - 1; i++) {
                            CellRangeAddress cra = new CellRangeAddress(sheetRow, pageRow, i, i);
                            regions.add(new XlsRegion(cra, null));
                        }
                    }
                }
                int cols = XlsUtil.copyToSheet(xlsSheet, sheetRow, sheetColumn, subreportSheet);
                addRegions(xlsSheet, subExporter.getSubreportRegions(), wb);
                if (ReportLayout.HEADER_BAND_NAME.equals(bandName)) {
                    prevSubreportFirstRow = gridRow;
                    prevSubreportFirstColumn = sheetColumn;
                    prevSubreportLastColumn = sheetColumn + cols;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if ((eb != null) && (eb.getResult() != null)) {
                    eb.getResult().close();
                }
            }
        } else if (bandElement instanceof ImageColumnBandElement) {
            try {
                ImageColumnBandElement icbe = (ImageColumnBandElement) bandElement;
                String v = StringUtil.getValueAsString(value, null);
                if (StringUtil.BLOB.equals(v)) {
                    c.setCellType(HSSFCell.CELL_TYPE_STRING);
                    c.setCellValue(new HSSFRichTextString(StringUtil.BLOB));
                } else {
                    byte[] imageD = StringUtil.decodeImage(v);
                    byte[] imageBytes = getImage(imageD, icbe.getWidth(), icbe.getHeight());
                    HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) sheetColumn, sheetRow,
                            (short) (sheetColumn + colSpan), (sheetRow + rowSpan));
                    int index = wb.addPicture(imageBytes, HSSFWorkbook.PICTURE_TYPE_JPEG);

                    // image is created over the cells, so if it's height is bigger we set the row height
                    short height = xlsRow.getHeight();
                    int realImageHeight = getRealImageSize(imageBytes)[1];
                    if (icbe.isScaled()) {
                        realImageHeight = icbe.getHeight();
                    }
                    short imageHeight = (short) (realImageHeight * POINTS_FOR_PIXEL / 2.5);
                    if (imageHeight > height) {
                        xlsRow.setHeight(imageHeight);
                    }

                    HSSFPicture picture = patriarch.createPicture(anchor, index);
                    picture.resize();
                    anchor.setAnchorType(2);
                }
            } catch (Exception e) {
                e.printStackTrace();
                c.setCellType(HSSFCell.CELL_TYPE_STRING);
                c.setCellValue(new HSSFRichTextString(IMAGE_NOT_LOADED));
            }

        } else {

            if (value == null) {
                c.setCellType(HSSFCell.CELL_TYPE_STRING);
                c.setCellValue(new HSSFRichTextString(""));
            } else if (value instanceof Number) {
                c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                c.setCellValue(((Number) value).doubleValue());
            } else {
                String pattern = null;
                if (bandElement instanceof FieldBandElement) {
                    FieldBandElement fbe = (FieldBandElement) bandElement;
                    pattern = fbe.getPattern();
                }
                if ((value instanceof java.sql.Date) || (value instanceof java.sql.Timestamp)) {
                    Date date;
                    if (value instanceof java.sql.Date) {
                        date = new Date(((java.sql.Date) value).getTime());
                    } else {
                        date = (java.sql.Timestamp) value;
                    }
                    if (cellStyle != null) {
                        if (pattern == null) {
                            // use default pattern if none selected
                            Locale locale = Locale.getDefault();
                            pattern = ((SimpleDateFormat) DateFormat.getDateInstance(SimpleDateFormat.MEDIUM,
                                    locale)).toPattern();
                        } else {
                            pattern = StringUtil.getI18nString(pattern, getReportLanguage());
                        }
                        cellStyle.setDataFormat(wb.createDataFormat().getFormat(pattern));
                    }
                    c.setCellValue(date);
                } else {
                    c.setCellType(HSSFCell.CELL_TYPE_STRING);
                    String text = StringUtil.getValueAsString(value, pattern);
                    if ((bandElement != null) && bandElement.isWrapText()) {
                        // try to interpret new line characters
                        // \\n is used here to be possible to add in designer grid cell with \n
                        if (text.contains("\\n") || text.contains("\n") || text.contains("\r")
                                || text.contains("\r\n")) {
                            String crLf = Character.toString((char) 13) + Character.toString((char) 10);
                            int lines = countLines(text);
                            if (text.contains("\r\n")) {
                                text = text.replaceAll("\r\n", crLf);
                            } else {
                                text = text.replaceAll("(\n)|(\r)|(\\\\n)", crLf);
                            }
                            c.setCellValue(text);
                            cellStyle.setWrapText(true);
                            xlsRow.setHeightInPoints(
                                    lines * (cellStyle.getFont(wb).getFontHeightInPoints() + 3));
                        } else {
                            c.setCellValue(new HSSFRichTextString(text));
                        }
                    } else {
                        c.setCellValue(new HSSFRichTextString(text));
                    }

                }
            }
        }

        if (cellStyle != null) {
            if (bandElement != null) {
                cellStyle.setRotation(bandElement.getTextRotation());
            }
            if (!(bandElement instanceof ReportBandElement)) {
                c.setCellStyle(cellStyle);
            }
        }

        if ((rowSpan > 1) || (colSpan > 1)) {
            CellRangeAddress cra = new CellRangeAddress(sheetRow, sheetRow + rowSpan - 1, sheetColumn,
                    sheetColumn + colSpan - 1);
            Border beBorder = bandElement.getBorder();
            if (hasRowRenderConditions(bandElement, gridRow, value)) {
                // for row render conditions we must keep the row border
                beBorder = border;
            }
            regions.add(new XlsRegion(cra, beBorder));
        }

    }
}