Java 类org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide 实例源码

项目:poilight    文件:PoiLightStyle.java   
/**
 * Fixed all properties suitable for cell-related style.
 * 
 * @param workbook Excel Workbook
 * @param boardStyle all properties suitable on the style of a cell
 * @param font a font
 * @return the customized style
 */
protected static CellStyle getCellStyle(Workbook workbook, TableStyle boardStyle, Font font) {
  XSSFCellStyle cellStyle = (XSSFCellStyle) workbook.createCellStyle();
  if (boardStyle.getFillColor() != null) {
    cellStyle.setFillForegroundColor(boardStyle.getFillColor());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
  }
  cellStyle.setBorderLeft(boardStyle.getCellBorderLeft());
  cellStyle.setBorderRight(boardStyle.getCellBorderRight());
  cellStyle.setBorderTop(boardStyle.getCellBorderTop());
  cellStyle.setBorderBottom(boardStyle.getCellBorderBottom());
  cellStyle.setAlignment(boardStyle.getAlignment());

  cellStyle.setBorderColor(BorderSide.LEFT, boardStyle.getBorderColor());
  cellStyle.setBorderColor(BorderSide.RIGHT, boardStyle.getBorderColor());
  cellStyle.setBorderColor(BorderSide.TOP, boardStyle.getBorderColor());
  cellStyle.setBorderColor(BorderSide.BOTTOM, boardStyle.getBorderColor());

  if (font != null) {
    cellStyle.setFont(font);
  }
  return cellStyle;
}
项目:vaadin-excel-exporter    文件:ExcelStyleUtil.java   
/**
 * Sets the borders.
 *
 * @param headerCellStyle
 *            the header cell style
 * @param left
 *            the left
 * @param right
 *            the right
 * @param top
 *            the top
 * @param bottom
 *            the bottom
 * @param color
 *            the color
 * @return the XSSF cell style
 */
public static XSSFCellStyle setBorders(final XSSFCellStyle headerCellStyle, final Boolean left, final Boolean right,
        final Boolean top, final Boolean bottom, final Color color) {
    if (bottom) {
        headerCellStyle.setBorderBottom(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(color));
    }

    if (top) {
        headerCellStyle.setBorderTop(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.TOP, new XSSFColor(color));
    }

    if (left) {
        headerCellStyle.setBorderLeft(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(color));
    }

    if (right) {
        headerCellStyle.setBorderRight(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(color));
    }

    return headerCellStyle;
}
项目:birt    文件:StyleManagerXUtils.java   
@Override
public void applyBorderStyle(Workbook workbook, CellStyle style, BorderSide side, CSSValue colour, CSSValue borderStyle, CSSValue width) {
    if( ( colour != null ) || ( borderStyle != null ) || ( width != null ) ) {
        String colourString = colour == null ? "rgb(0,0,0)" : colour.getCssText();
        String borderStyleString = borderStyle == null ? "solid" : borderStyle.getCssText();
        String widthString = width == null ? "medium" : width.getCssText();

        if( style instanceof XSSFCellStyle ) {
            XSSFCellStyle xStyle = (XSSFCellStyle)style;

            BorderStyle xBorderStyle = poiBorderStyleFromBirt(borderStyleString, widthString);
            XSSFColor xBorderColour = getXColour(colourString);
            if(xBorderStyle != BorderStyle.NONE) {
                switch( side ) {
                case TOP:
                    xStyle.setBorderTop(xBorderStyle);
                    xStyle.setTopBorderColor(xBorderColour);
                    // log.debug( "Top border: " + xStyle.getBorderTop() + " / " + xStyle.getTopBorderXSSFColor().getARGBHex() );
                    break;
                case LEFT:
                    xStyle.setBorderLeft(xBorderStyle);
                    xStyle.setLeftBorderColor(xBorderColour);
                    // log.debug( "Left border: " + xStyle.getBorderLeft() + " / " + xStyle.getLeftBorderXSSFColor().getARGBHex() );
                    break;
                case RIGHT:
                    xStyle.setBorderRight(xBorderStyle);
                    xStyle.setRightBorderColor(xBorderColour);
                    // log.debug( "Right border: " + xStyle.getBorderRight() + " / " + xStyle.getRightBorderXSSFColor().getARGBHex() );
                    break;
                case BOTTOM:
                    xStyle.setBorderBottom(xBorderStyle);
                    xStyle.setBottomBorderColor(xBorderColour);
                    // log.debug( "Bottom border: " + xStyle.getBorderBottom() + " / " + xStyle.getBottomBorderXSSFColor().getARGBHex() );
                    break;
                }
            }
        }
    }
}
项目:birt    文件:StyleManager.java   
/**
 * Create a new POI CellStyle based upon a BIRT style.
 * @param birtStyle
 * The BIRT style to base the CellStyle upon.
 * @return
 * The CellStyle whose attributes are described by the BIRT style. 
 */
private CellStyle createStyle( BirtStyle birtStyle ) {
    CellStyle poiStyle = workbook.createCellStyle();
    // Font
    Font font = fm.getFont(birtStyle);
    if( font != null ) {
        poiStyle.setFont(font);
    }
    // Alignment
    poiStyle.setAlignment(smu.poiAlignmentFromBirtAlignment(birtStyle.getString( StyleConstants.STYLE_TEXT_ALIGN )));
    // Background colour
    smu.addBackgroundColourToStyle(workbook, poiStyle, birtStyle.getString( StyleConstants.STYLE_BACKGROUND_COLOR ));
    // Top border 
    smu.applyBorderStyle(workbook, poiStyle, BorderSide.TOP, birtStyle.getProperty(StyleConstants.STYLE_BORDER_TOP_COLOR), birtStyle.getProperty(StyleConstants.STYLE_BORDER_TOP_STYLE), birtStyle.getProperty(StyleConstants.STYLE_BORDER_TOP_WIDTH));
    // Left border 
    smu.applyBorderStyle(workbook, poiStyle, BorderSide.LEFT, birtStyle.getProperty(StyleConstants.STYLE_BORDER_LEFT_COLOR), birtStyle.getProperty(StyleConstants.STYLE_BORDER_LEFT_STYLE), birtStyle.getProperty(StyleConstants.STYLE_BORDER_LEFT_WIDTH));
    // Right border 
    smu.applyBorderStyle(workbook, poiStyle, BorderSide.RIGHT, birtStyle.getProperty(StyleConstants.STYLE_BORDER_RIGHT_COLOR), birtStyle.getProperty(StyleConstants.STYLE_BORDER_RIGHT_STYLE), birtStyle.getProperty(StyleConstants.STYLE_BORDER_RIGHT_WIDTH));
    // Bottom border 
    smu.applyBorderStyle(workbook, poiStyle, BorderSide.BOTTOM, birtStyle.getProperty(StyleConstants.STYLE_BORDER_BOTTOM_COLOR), birtStyle.getProperty(StyleConstants.STYLE_BORDER_BOTTOM_STYLE), birtStyle.getProperty(StyleConstants.STYLE_BORDER_BOTTOM_WIDTH));
    // Number format
    smu.applyNumberFormat(workbook, birtStyle, poiStyle, locale);
    // Whitespace/wrap
    if( CSSConstants.CSS_PRE_VALUE.equals( birtStyle.getString( StyleConstants.STYLE_WHITE_SPACE ) ) ) {
        poiStyle.setWrapText( true );
    }
    // Vertical alignment
    if( CSSConstants.CSS_TOP_VALUE.equals( birtStyle.getString( StyleConstants.STYLE_VERTICAL_ALIGN ) ) ) {
        poiStyle.setVerticalAlignment( CellStyle.VERTICAL_TOP );
    } else if ( CSSConstants.CSS_MIDDLE_VALUE.equals( birtStyle.getString( StyleConstants.STYLE_VERTICAL_ALIGN ) ) ) {
        poiStyle.setVerticalAlignment( CellStyle.VERTICAL_CENTER );
    } else if ( CSSConstants.CSS_BOTTOM_VALUE.equals( birtStyle.getString( StyleConstants.STYLE_VERTICAL_ALIGN ) ) ) {
        poiStyle.setVerticalAlignment( CellStyle.VERTICAL_BOTTOM );
    } 
    // Rotation
    CSSValue rotation = birtStyle.getProperty( BirtStyle.TEXT_ROTATION );
    if( rotation instanceof FloatValue ) {
        poiStyle.setRotation( (short) ((FloatValue)rotation).getFloatValue() );
    }

    styles.add(new StylePair( birtStyle.clone(), poiStyle ) );
    return poiStyle;
}
项目:birt    文件:StyleManagerHUtils.java   
@Override
public void applyBorderStyle(Workbook workbook, CellStyle style, BorderSide side, CSSValue colour, CSSValue borderStyle, CSSValue width) {
    if( ( colour != null ) || ( borderStyle != null ) || ( width != null ) ) {
        String colourString = colour == null ? "rgb(0,0,0)" : colour.getCssText();
        String borderStyleString = borderStyle == null ? "solid" : borderStyle.getCssText();
        String widthString = width == null ? "medium" : width.getCssText();

        if( style instanceof HSSFCellStyle ) {
            HSSFCellStyle hStyle = (HSSFCellStyle)style;

            short hBorderStyle = poiBorderStyleFromBirt(borderStyleString, widthString);
            short colourIndex = getHColour((HSSFWorkbook)workbook, colourString);
            if( colourIndex > 0 ) {
                if(hBorderStyle != CellStyle.BORDER_NONE) {
                    switch( side ) {
                    case TOP:
                        hStyle.setBorderTop(hBorderStyle);
                        hStyle.setTopBorderColor(colourIndex);
                        // log.debug( "Top border: " + xStyle.getBorderTop() + " / " + xStyle.getTopBorderXSSFColor().getARGBHex() );
                        break;
                    case LEFT:
                        hStyle.setBorderLeft(hBorderStyle);
                        hStyle.setLeftBorderColor(colourIndex);
                        // log.debug( "Left border: " + xStyle.getBorderLeft() + " / " + xStyle.getLeftBorderXSSFColor().getARGBHex() );
                        break;
                    case RIGHT:
                        hStyle.setBorderRight(hBorderStyle);
                        hStyle.setRightBorderColor(colourIndex);
                        // log.debug( "Right border: " + xStyle.getBorderRight() + " / " + xStyle.getRightBorderXSSFColor().getARGBHex() );
                        break;
                    case BOTTOM:
                        hStyle.setBorderBottom(hBorderStyle);
                        hStyle.setBottomBorderColor(colourIndex);
                        // log.debug( "Bottom border: " + xStyle.getBorderBottom() + " / " + xStyle.getBottomBorderXSSFColor().getARGBHex() );
                        break;
                    }
                }
            }
        }
    }
}
项目:birt    文件:StyleManagerUtils.java   
/**
 * Apply a BIRT border style to one side of a POI CellStyle.
 * @param workbook
 * The workbook that contains the cell being styled.
 * @param style
 * The POI CellStyle that is to have the border applied to it. 
 * @param side
 * The side of the border that is to be applied.<br>
 * Note that although this value is from XSSFCellBorder it is equally valid for HSSFCellStyles.
 * @param colour
 * The colour for the new border.
 * @param borderStyle
 * The BIRT style for the new border.
 * @param width
 * The width of the new border.
 */
public abstract void applyBorderStyle(Workbook workbook, CellStyle style, BorderSide side, CSSValue colour, CSSValue borderStyle, CSSValue width);