Java Code Examples for org.apache.poi.ss.usermodel.CellStyle#setRotation()

The following examples show how to use org.apache.poi.ss.usermodel.CellStyle#setRotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellUtil.java    From lams with GNU General Public License v2.0 8 votes vote down vote up
/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
    style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
    style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
    style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
    style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
    style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
    style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
    style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
    style.setDataFormat(getShort(properties, DATA_FORMAT));
    style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
    style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
    style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
    style.setFont(workbook.getFontAt(getShort(properties, FONT)));
    style.setHidden(getBoolean(properties, HIDDEN));
    style.setIndention(getShort(properties, INDENTION));
    style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
    style.setLocked(getBoolean(properties, LOCKED));
    style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
    style.setRotation(getShort(properties, ROTATION));
    style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
    style.setWrapText(getBoolean(properties, WRAP_TEXT));
}
 
Example 2
Source File: ExcelUtil.java    From danyuan-application with Apache License 2.0 5 votes vote down vote up
/**
 * 复制一个单元格样式到目的单元格样式
 *
 * @param fromStyle
 * @param toStyle
 */
public static void copyCellStyle(CellStyle fromStyle, CellStyle toStyle) {
	toStyle.setAlignment(fromStyle.getAlignmentEnum());
	// 边框和边框颜色
	toStyle.setBorderBottom(fromStyle.getBorderBottomEnum());
	toStyle.setBorderLeft(fromStyle.getBorderLeftEnum());
	toStyle.setBorderRight(fromStyle.getBorderRightEnum());
	toStyle.setBorderTop(fromStyle.getBorderTopEnum());
	toStyle.setTopBorderColor(fromStyle.getTopBorderColor());
	toStyle.setBottomBorderColor(fromStyle.getBottomBorderColor());
	toStyle.setRightBorderColor(fromStyle.getRightBorderColor());
	toStyle.setLeftBorderColor(fromStyle.getLeftBorderColor());
	
	// 背景和前景
	toStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor());
	toStyle.setFillForegroundColor(fromStyle.getFillForegroundColor());
	
	// 数据格式
	toStyle.setDataFormat(fromStyle.getDataFormat());
	toStyle.setFillPattern(fromStyle.getFillPatternEnum());
	// toStyle.setFont(fromStyle.getFont(null));
	toStyle.setHidden(fromStyle.getHidden());
	toStyle.setIndention(fromStyle.getIndention());// 首行缩进
	toStyle.setLocked(fromStyle.getLocked());
	toStyle.setRotation(fromStyle.getRotation());// 旋转
	toStyle.setVerticalAlignment(fromStyle.getVerticalAlignmentEnum());
	toStyle.setWrapText(fromStyle.getWrapText());
	
}
 
Example 3
Source File: Rotation.java    From excel-io with MIT License 4 votes vote down vote up
@Override
public void accept(final CellStyle style) {
    style.setRotation(this.value);
}
 
Example 4
Source File: StyleUtil.java    From easyexcel with Apache License 2.0 4 votes vote down vote up
private static void buildCellStyle(Workbook workbook, CellStyle cellStyle, WriteCellStyle writeCellStyle,
    boolean isHead) {
    buildFont(workbook, cellStyle, writeCellStyle.getWriteFont(), isHead);
    if (writeCellStyle.getDataFormat() != null) {
        cellStyle.setDataFormat(writeCellStyle.getDataFormat());
    }
    if (writeCellStyle.getHidden() != null) {
        cellStyle.setHidden(writeCellStyle.getHidden());
    }
    if (writeCellStyle.getLocked() != null) {
        cellStyle.setLocked(writeCellStyle.getLocked());
    }
    if (writeCellStyle.getQuotePrefix() != null) {
        cellStyle.setQuotePrefixed(writeCellStyle.getQuotePrefix());
    }
    if (writeCellStyle.getHorizontalAlignment() != null) {
        cellStyle.setAlignment(writeCellStyle.getHorizontalAlignment());
    }
    if (writeCellStyle.getWrapped() != null) {
        cellStyle.setWrapText(writeCellStyle.getWrapped());
    }
    if (writeCellStyle.getVerticalAlignment() != null) {
        cellStyle.setVerticalAlignment(writeCellStyle.getVerticalAlignment());
    }
    if (writeCellStyle.getRotation() != null) {
        cellStyle.setRotation(writeCellStyle.getRotation());
    }
    if (writeCellStyle.getIndent() != null) {
        cellStyle.setIndention(writeCellStyle.getIndent());
    }
    if (writeCellStyle.getBorderLeft() != null) {
        cellStyle.setBorderLeft(writeCellStyle.getBorderLeft());
    }
    if (writeCellStyle.getBorderRight() != null) {
        cellStyle.setBorderRight(writeCellStyle.getBorderRight());
    }
    if (writeCellStyle.getBorderTop() != null) {
        cellStyle.setBorderTop(writeCellStyle.getBorderTop());
    }
    if (writeCellStyle.getBorderBottom() != null) {
        cellStyle.setBorderBottom(writeCellStyle.getBorderBottom());
    }
    if (writeCellStyle.getLeftBorderColor() != null) {
        cellStyle.setLeftBorderColor(writeCellStyle.getLeftBorderColor());
    }
    if (writeCellStyle.getRightBorderColor() != null) {
        cellStyle.setRightBorderColor(writeCellStyle.getRightBorderColor());
    }
    if (writeCellStyle.getTopBorderColor() != null) {
        cellStyle.setTopBorderColor(writeCellStyle.getTopBorderColor());
    }
    if (writeCellStyle.getBottomBorderColor() != null) {
        cellStyle.setBottomBorderColor(writeCellStyle.getBottomBorderColor());
    }
    if (writeCellStyle.getFillPatternType() != null) {
        cellStyle.setFillPattern(writeCellStyle.getFillPatternType());
    }
    if (writeCellStyle.getFillBackgroundColor() != null) {
        cellStyle.setFillBackgroundColor(writeCellStyle.getFillBackgroundColor());
    }
    if (writeCellStyle.getFillForegroundColor() != null) {
        cellStyle.setFillForegroundColor(writeCellStyle.getFillForegroundColor());
    }
    if (writeCellStyle.getShrinkToFit() != null) {
        cellStyle.setShrinkToFit(writeCellStyle.getShrinkToFit());
    }
}
 
Example 5
Source File: Util.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private static void copyCell(Cell oldCell, Cell newCell, List<CellStyle> styleList) {
	if (styleList != null) {
		if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
			newCell.setCellStyle(oldCell.getCellStyle());
		} else {
			DataFormat newDataFormat = newCell.getSheet().getWorkbook().createDataFormat();

			CellStyle newCellStyle = getSameCellStyle(oldCell, newCell, styleList);
			if (newCellStyle == null) {

				Font oldFont = oldCell.getSheet().getWorkbook().getFontAt(oldCell.getCellStyle().getFontIndex());

				Font newFont = newCell.getSheet().getWorkbook().findFont(oldFont.getBoldweight(), oldFont.getColor(), oldFont.getFontHeight(),
						oldFont.getFontName(), oldFont.getItalic(), oldFont.getStrikeout(), oldFont.getTypeOffset(), oldFont.getUnderline());
				if (newFont == null) {
					newFont = newCell.getSheet().getWorkbook().createFont();
					newFont.setBoldweight(oldFont.getBoldweight());
					newFont.setColor(oldFont.getColor());
					newFont.setFontHeight(oldFont.getFontHeight());
					newFont.setFontName(oldFont.getFontName());
					newFont.setItalic(oldFont.getItalic());
					newFont.setStrikeout(oldFont.getStrikeout());
					newFont.setTypeOffset(oldFont.getTypeOffset());
					newFont.setUnderline(oldFont.getUnderline());
					newFont.setCharSet(oldFont.getCharSet());
				}

				short newFormat = newDataFormat.getFormat(oldCell.getCellStyle().getDataFormatString());
				newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
				newCellStyle.setFont(newFont);
				newCellStyle.setDataFormat(newFormat);

				newCellStyle.setAlignment(oldCell.getCellStyle().getAlignment());
				newCellStyle.setHidden(oldCell.getCellStyle().getHidden());
				newCellStyle.setLocked(oldCell.getCellStyle().getLocked());
				newCellStyle.setWrapText(oldCell.getCellStyle().getWrapText());
				newCellStyle.setBorderBottom(oldCell.getCellStyle().getBorderBottom());
				newCellStyle.setBorderLeft(oldCell.getCellStyle().getBorderLeft());
				newCellStyle.setBorderRight(oldCell.getCellStyle().getBorderRight());
				newCellStyle.setBorderTop(oldCell.getCellStyle().getBorderTop());
				newCellStyle.setBottomBorderColor(oldCell.getCellStyle().getBottomBorderColor());
				newCellStyle.setFillBackgroundColor(oldCell.getCellStyle().getFillBackgroundColor());
				newCellStyle.setFillForegroundColor(oldCell.getCellStyle().getFillForegroundColor());
				newCellStyle.setFillPattern(oldCell.getCellStyle().getFillPattern());
				newCellStyle.setIndention(oldCell.getCellStyle().getIndention());
				newCellStyle.setLeftBorderColor(oldCell.getCellStyle().getLeftBorderColor());
				newCellStyle.setRightBorderColor(oldCell.getCellStyle().getRightBorderColor());
				newCellStyle.setRotation(oldCell.getCellStyle().getRotation());
				newCellStyle.setTopBorderColor(oldCell.getCellStyle().getTopBorderColor());
				newCellStyle.setVerticalAlignment(oldCell.getCellStyle().getVerticalAlignment());

				styleList.add(newCellStyle);
			}
			newCell.setCellStyle(newCellStyle);
		}
	}
	switch (oldCell.getCellType()) {
	case Cell.CELL_TYPE_STRING:
		newCell.setCellValue(oldCell.getStringCellValue());
		break;
	case Cell.CELL_TYPE_NUMERIC:
		newCell.setCellValue(oldCell.getNumericCellValue());
		break;
	case Cell.CELL_TYPE_BLANK:
		newCell.setCellType(Cell.CELL_TYPE_BLANK);
		break;
	case Cell.CELL_TYPE_BOOLEAN:
		newCell.setCellValue(oldCell.getBooleanCellValue());
		break;
	case Cell.CELL_TYPE_ERROR:
		newCell.setCellErrorValue(oldCell.getErrorCellValue());
		break;
	case Cell.CELL_TYPE_FORMULA:
		newCell.setCellFormula(oldCell.getCellFormula());
		formulaInfoList.add(new FormulaInfo(oldCell.getSheet().getSheetName(), oldCell.getRowIndex(), oldCell.getColumnIndex(), oldCell.getCellFormula()));
		break;
	default:
		break;
	}
}
 
Example 6
Source File: StyleManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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;
}