Example usage for org.apache.poi.ss.usermodel CellStyle getIndex

List of usage examples for org.apache.poi.ss.usermodel CellStyle getIndex

Introduction

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

Prototype

short getIndex();

Source Link

Document

get the index within the Workbook (sequence within the collection of ExtnededFormat objects)

Usage

From source file:com.vaadin.addon.spreadsheet.SpreadsheetStyleFactory.java

License:Open Source License

private void borderStyles(StringBuilder sb, CellStyle cellStyle) {

    BorderStyle borderLeft = BORDER.get(cellStyle.getBorderLeft());
    BorderStyle borderRight = BORDER.get(cellStyle.getBorderRight());
    BorderStyle borderTop = BORDER.get(cellStyle.getBorderTop());
    BorderStyle borderBottom = BORDER.get(cellStyle.getBorderBottom());

    if (cellStyle instanceof XSSFCellStyle && !((XSSFCellStyle) cellStyle).getCoreXf().getApplyBorder()) {
        // borders from theme are not working in POI 3.9
        final CTXf _cellXf = ((XSSFCellStyle) cellStyle).getCoreXf();
        int idx = (int) _cellXf.getBorderId();
        CTBorder ct = ((XSSFWorkbook) spreadsheet.getWorkbook()).getStylesSource().getBorderAt(idx)
                .getCTBorder();/* w ww.j  a v a2  s.  c  om*/

        if (borderLeft == BorderStyle.NONE) {
            STBorderStyle.Enum ptrn = ct.isSetLeft() ? ct.getLeft().getStyle() : null;
            if (ptrn != null) {
                Short key = (short) (ptrn.intValue() - 1);
                borderLeft = BORDER.get(key);
            }
        }
        if (borderRight == BorderStyle.NONE) {
            STBorderStyle.Enum ptrn = ct.isSetRight() ? ct.getRight().getStyle() : null;
            if (ptrn != null) {
                Short key = (short) (ptrn.intValue() - 1);
                borderRight = BORDER.get(key);
            }
        }
        if (borderBottom == BorderStyle.NONE) {
            STBorderStyle.Enum ptrn = ct.isSetBottom() ? ct.getBottom().getStyle() : null;
            if (ptrn != null) {
                Short key = (short) (ptrn.intValue() - 1);
                borderBottom = BORDER.get(key);
            }
        }
        if (borderTop == BorderStyle.NONE) {
            STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null;
            if (ptrn != null) {
                Short key = (short) (ptrn.intValue() - 1);
                borderTop = BORDER.get(key);
            }

        }
    }

    if (borderRight != BorderStyle.NONE) {
        sb.append("border-right:");
        sb.append(borderRight.getBorderAttributeValue());
        sb.append(colorConverter.getBorderColorCSS(BorderSide.RIGHT, "border-right-color", cellStyle));
    }
    if (borderBottom != BorderStyle.NONE) {
        sb.append("border-bottom:");
        sb.append(borderBottom.getBorderAttributeValue());
        sb.append(colorConverter.getBorderColorCSS(BorderSide.BOTTOM, "border-bottom-color", cellStyle));
    }

    // the top and right borders are transferred to previous cells
    if (borderTop != BorderStyle.NONE || borderLeft != BorderStyle.NONE) {
        if (borderTop != BorderStyle.NONE) {
            final StringBuilder sb2 = new StringBuilder("{border-bottom:");
            sb2.append(borderTop.getBorderAttributeValue());
            sb2.append(colorConverter.getBorderColorCSS(BorderSide.TOP, "border-bottom-color", cellStyle));
            sb2.append("}");
            shiftedBorderTopStyles.put((int) cellStyle.getIndex(), sb2.toString());
        }
        if (borderLeft != BorderStyle.NONE) {
            final StringBuilder sb2 = new StringBuilder("{border-right:");
            sb2.append(borderLeft.getBorderAttributeValue());
            sb2.append(colorConverter.getBorderColorCSS(BorderSide.LEFT, "border-right-color", cellStyle));
            sb2.append("}");
            shiftedBorderLeftStyles.put((int) cellStyle.getIndex(), sb2.toString());
        }
    }
}

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

License:Apache License

private void setupStyle(Cell cell, int row) {
    CellStyle style = cell.getCellStyle();
    // cell has its own style and not the default style
    if (reuseExistingStyles) {
        // we have to reuse the existing style
        if (reuseExistingStylesAlternating) {
            // we have to reuse the style from the even/odd row
            if (isFirstRow(row)) {
                // we are in the first row, memorize the style
                if (style.getIndex() > 0) {
                    // only if the cell does not use the default style
                    oddRowColumnStyleMap.put(cell.getColumnIndex(), style);
                }/*from   w  w w  .j a v  a  2s.co m*/
            } else if (isSecondRow(row)) {
                // we are in the first row, memorize the style
                if (style.getIndex() > 0) {
                    // only if the cell does not use the default style
                    evenRowColumnStyleMap.put(cell.getColumnIndex(), style);
                }
            } else if (isEvenDataRow(row)) {
                // reference to the previously memorized style for even rows
                CellStyle s = evenRowColumnStyleMap.get(cell.getColumnIndex());
                if (s != null) {
                    style = s;
                    cell.setCellStyle(style);
                }
            } else {
                // reference to the previously memorized style for even rows
                CellStyle s = oddRowColumnStyleMap.get(cell.getColumnIndex());
                if (s != null) {
                    style = s;
                    cell.setCellStyle(style);
                }
            }
        } else {
            // we take the style from the last row
            if (isFirstRow(row)) {
                // memorize the style for reuse in all other rows
                if (style.getIndex() > 0) {
                    // only if the cell does not use the default style
                    columnStyleMap.put(cell.getColumnIndex(), style);
                }
            } else {
                // set the style from the previous row
                CellStyle s = columnStyleMap.get(cell.getColumnIndex());
                if (s != null) {
                    style = s;
                    cell.setCellStyle(style);
                }
            }
        }
    } else {
        Short formatIndex = cellFormatMap.get(cell.getColumnIndex());
        if (formatIndex != null) {
            if ((style.getIndex() == 0) || (style.getDataFormat() != formatIndex)) {
                // this is the default style or the current format differs from the given format
                // we need our own style for this 
                style = columnStyleMap.get(cell.getColumnIndex());
                if (style == null) {
                    style = workbook.createCellStyle();
                    style.setDataFormat(formatIndex.shortValue());
                    columnStyleMap.put(cell.getColumnIndex(), style);
                }
                cell.setCellStyle(style);
            }
        }
    }
}

From source file:org.sysmodb.xml.XMLStyleGenerator.java

License:BSD License

public static void writeStyle(XMLStreamWriter xmlWriter, CellStyle style, XMLStyleHelper helper)
        throws XMLStreamException {
    String border = "none";
    xmlWriter.writeStartElement("style");
    xmlWriter.writeAttribute("id", "style" + style.getIndex());
    if ((border = BORDERS.get(style.getBorderTopEnum())) != "none") {
        xmlWriter.writeStartElement("border-top");
        xmlWriter.writeCharacters(border);
        xmlWriter.writeEndElement();/*from  w  w  w.j a va 2 s . c o m*/
    }

    if ((border = BORDERS.get(style.getBorderBottomEnum())) != "none") {
        xmlWriter.writeStartElement("border-bottom");
        xmlWriter.writeCharacters(border);
        xmlWriter.writeEndElement();
    }

    if ((border = BORDERS.get(style.getBorderLeftEnum())) != "none") {
        xmlWriter.writeStartElement("border-left");
        xmlWriter.writeCharacters(border);
        xmlWriter.writeEndElement();
    }

    if ((border = BORDERS.get(style.getBorderRightEnum())) != "none") {
        xmlWriter.writeStartElement("border-right");
        xmlWriter.writeCharacters(border);
        xmlWriter.writeEndElement();
    }

    // Background/fill colour
    String backgroundColour;
    if ((backgroundColour = helper.getBGColour(style)) != null) {
        xmlWriter.writeStartElement("background-color");
        xmlWriter.writeCharacters(backgroundColour);
        xmlWriter.writeEndElement();
    }

    helper.writeFontProperties(xmlWriter, style);

    xmlWriter.writeEndElement();

}

From source file:ru.spb.nicetu.tableviewer.server.XlsToHtml.java

License:Apache License

private String styleName(CellStyle style, Formatter out) {
    if (style == null)
        style = wb.getCellStyleAt((short) 0);
    StringBuilder sb = new StringBuilder();
    Formatter fmt = new Formatter(sb);
    try {// w  ww. jav a2 s .  c o  m
        fmt.format("style_%02x", style.getIndex());
        return fmt.toString();
    } finally {
        fmt.close();
    }
}

From source file:sol.neptune.elisaboard.service.VPlanToHtml.java

License:Apache License

private String styleName(CellStyle style) {
    if (style == null) {
        style = wb.getCellStyleAt((short) 0);
    }/* ww  w  . ja v a  2 s  . c  o m*/
    StringBuilder sb = new StringBuilder();
    Formatter fmt = new Formatter(sb);
    fmt.format("style_%02x", style.getIndex());
    return fmt.toString();
}

From source file:uk.co.certait.test.ExcelToHtmlConverter.java

License:Apache License

private String styleName(CellStyle style) {
    if (style == null) {
        style = wb.getCellStyleAt((short) 0);
    }/*from   w  w w .  j a v  a 2  s.c  o  m*/
    StringBuilder sb = new StringBuilder();
    Formatter fmt = new Formatter(sb);
    try {
        fmt.format("style_%02x", style.getIndex());
        return fmt.toString();
    } finally {
        fmt.close();
    }
}