org.apache.poi.ss.usermodel.VerticalAlignment Java Examples

The following examples show how to use org.apache.poi.ss.usermodel.VerticalAlignment. 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: ExcelExportSuper.java    From phone with Apache License 2.0 7 votes vote down vote up
/**
 * 表头条件
 * @param sheet
 * @param t
 * @param cellCount
 * @return
 */
void writeCondtions(HSSFSheet sheet){
	T t = getConditions();
	if (t!=null) {
		HSSFRow row = sheet.createRow(getRowNumber());
		row.setHeight((short) 500);
		CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size());
		sheet.addMergedRegion(cra);
		HSSFCell cell = row.createCell(0);
		HSSFCellStyle style = cell.getCellStyle();
		style.setAlignment(HorizontalAlignment.CENTER);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setWrapText(true);
		cell.setCellStyle(style);
		setCellValue(cell, formatCondition(t));
		addRowNumber();
	}
}
 
Example #2
Source File: XLSPrinter.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected CellStyle getStyle(A f, boolean dashed, String format) {
	String styleId = (dashed ? "D" : "")
			+ (f.has(F.BOLD) ? "b" : "") + (f.has(F.ITALIC) ? "i" : "") + (f.has(F.UNDERLINE) ? "u" : "")
			+ (f.has(F.RIGHT) ? "R" : f.has(F.CENTER) ? "C" : "L")
			+ (f.hasColor() ? "#" + Integer.toHexString(f.getColor().getRGB()) : "")
			+ (format == null ? "" : "|" + format);
	CellStyle style = iStyles.get(styleId);
	if (style == null) {
		style = iWorkbook.createCellStyle();
		if (dashed) {
			style.setBorderTop(BorderStyle.DASHED);
	        style.setTopBorderColor(IndexedColors.BLACK.getIndex());
		}
		style.setAlignment(f.has(F.RIGHT) ? HorizontalAlignment.RIGHT : f.has(F.CENTER) ? HorizontalAlignment.CENTER : HorizontalAlignment.LEFT);
		style.setVerticalAlignment(VerticalAlignment.TOP);
		style.setFont(getFont(f.has(F.BOLD), f.has(F.ITALIC), f.has(F.UNDERLINE), f.getColor()));
       	style.setWrapText(true);
       	if (format != null)
       		style.setDataFormat(iWorkbook.createDataFormat().getFormat(format));
       	iStyles.put(styleId, style);
	}
	return style;
}
 
Example #3
Source File: WorkbookContext.java    From Octopus with MIT License 6 votes vote down vote up
public CellStyle getHeaderStyle(Field field) {
    CellStyle style = headerStyleMap.get(field);
    if (style == null) {
        style = book.createCellStyle();
        Font font = book.createFont();
        FieldCellStyle fieldCellStyle = field.getHeaderFieldCellStyle();


        font.setFontHeightInPoints(fieldCellStyle.getFontSize());
        font.setBold(fieldCellStyle.isBold());
        ColorUtils.setColor(book, font, fieldCellStyle.getColor());
        style.setFont(font);
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        ColorUtils.setForegroundColor(book, style, fieldCellStyle.getForegroundColor());

        setStyleBorder(style, fieldCellStyle.getBorder());
        ColorUtils.setBorderColor(book, style, fieldCellStyle.getBorderColor());
        cellStyleMap.put(field, style);
        return style;
    }
    return style;
}
 
Example #4
Source File: WorkbookContext.java    From Octopus with MIT License 6 votes vote down vote up
public CellStyle getCellStyle(Field field) {
    CellStyle style = cellStyleMap.get(field);
    if (style == null) {
        style = book.createCellStyle();
        Font font = book.createFont();
        FieldCellStyle fieldCellStyle = field.getFieldCellStyle();


        font.setFontHeightInPoints(fieldCellStyle.getFontSize());
        font.setBold(fieldCellStyle.isBold());
        ColorUtils.setColor(book, font, fieldCellStyle.getColor());
        style.setFont(font);
        ColorUtils.setForegroundColor(book, style, fieldCellStyle.getForegroundColor());

        setStyleBorder(style, fieldCellStyle.getBorder());
        ColorUtils.setBorderColor(book, style, fieldCellStyle.getBorderColor());

        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyleMap.put(field, style);
        return style;
    }
    return style;
}
 
Example #5
Source File: ExportTimetableXLS.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected CellStyle getHeaderIntervalStyle(P p) {
	String styleId = "header-interval";
	CellStyle style = iStyles.get(styleId);
	if (style == null) {
		style = iWorkbook.createCellStyle();
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
        if (p.getWidth() == 1) {
        	style.setBorderRight(BorderStyle.THIN);
        	style.setRightBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
        }
        style.setFont(getFont(p));
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.TOP);
        style.setWrapText(true);
        iStyles.put(styleId, style);
	}
	return style;
}
 
Example #6
Source File: ExportTimetableXLS.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected CellStyle getGridNameStyle(P p) {
	String styleId = "grid-name";
	CellStyle style = iStyles.get(styleId);
	if (style == null) {
		style = iWorkbook.createCellStyle();
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setFont(getFont(p));
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.TOP);
        style.setWrapText(true);
        iStyles.put(styleId, style);
	}
	return style;
}
 
Example #7
Source File: JRXlsExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
public StyleInfo(
	FillPatternType mode,
	short backcolor,
	HorizontalAlignment horizontalAlignment,
	VerticalAlignment verticalAlignment,
	short rotation,
	HSSFFont font,
	JRExporterGridCell gridCell,
	boolean wrapText,
	boolean cellLocked,
	boolean cellHidden,
	boolean shrinkToFit
	)
{
	this(mode, 
		backcolor, 
		horizontalAlignment, 
		verticalAlignment, 
		rotation, 
		font, 
		(gridCell == null ? null : new BoxStyle(gridCell)), 
		wrapText, 
		cellLocked, 
		cellHidden, 
		shrinkToFit);
}
 
Example #8
Source File: Over23CandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void exportXLSLine(final Sheet sheet, final CellStyle cellStyle, final List<Object> cells,
        final int offset) {

    final org.apache.poi.ss.usermodel.Row row = sheet.createRow(sheet.getLastRowNum() + offset);
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    int count = 0;
    for (final Object cellValue : cells) {
        if (++count == 3) {
            cellStyle.setAlignment(HorizontalAlignment.LEFT);
        } else {
            cellStyle.setAlignment(HorizontalAlignment.CENTER);
        }
        addColumn(cellStyle, row, cellValue);
    }
}
 
Example #9
Source File: Over23CandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void exportXLSLine(final Sheet sheet, final CellStyle cellStyle, final List<Object> cells,
        final int offset) {

    final org.apache.poi.ss.usermodel.Row row = sheet.createRow(sheet.getLastRowNum() + offset);
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    int count = 0;
    for (final Object cellValue : cells) {
        if (++count == 3) {
            cellStyle.setAlignment(HorizontalAlignment.LEFT);
        } else {
            cellStyle.setAlignment(HorizontalAlignment.CENTER);
        }
        addColumn(cellStyle, row, cellValue);
    }
}
 
Example #10
Source File: JRXlsExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected HSSFCellStyle getLoadedCellStyle(
	FillPatternType mode,
	short backcolor,
	HorizontalAlignment horizontalAlignment,
	VerticalAlignment verticalAlignment,
	short rotation,
	HSSFFont font,
	BoxStyle box,
	boolean isWrapText,
	boolean isCellLocked,
	boolean isCellHidden,
	boolean isShrinkToFit
	)
{
	StyleInfo style = new StyleInfo(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, box, isWrapText, isCellLocked, isCellHidden, isShrinkToFit);
	return getLoadedCellStyle(style);
}
 
Example #11
Source File: Style.java    From java-master with Apache License 2.0 6 votes vote down vote up
Style(String fontName, int fontColor, boolean fontBold, int fontUnderline, boolean fontItalic, int fontHeightInPoints,
      int foregroundColor, int backgroundColor, boolean needLeftBorder, boolean needRightBorder, boolean needTopBorder,
      boolean needBottomBorder, int borderColor, BorderStyle borderWeight, boolean autoLineFeed, HorizontalAlignment alignment,
      VerticalAlignment verticalAlignment, String datePattern, String decimalPattern) {
    this.fontName = fontName;
    this.fontColor = fontColor;
    this.fontBold = fontBold;
    this.fontUnderline = fontUnderline;
    this.fontItalic = fontItalic;
    this.fontHeightInPoints = fontHeightInPoints;
    this.foregroundColor = foregroundColor;
    this.backgroundColor = backgroundColor;
    this.needLeftBorder = needLeftBorder;
    this.needRightBorder = needRightBorder;
    this.needTopBorder = needTopBorder;
    this.needBottomBorder = needBottomBorder;
    this.borderColor = borderColor;
    this.borderWeight = borderWeight;
    this.autoLineFeed = autoLineFeed;
    this.alignment = alignment;
    this.verticalAlignment = verticalAlignment;
    this.datePattern = datePattern;
    this.decimalPattern = decimalPattern;
}
 
Example #12
Source File: ExcelCellStyleBuilderTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testElementStyleSet() {
  when( workbook.createCellStyle() ).thenReturn( xlsStyle );
  ExcelCellStyleBuilder builder = new ExcelCellStyleBuilder( workbook );
  when( workbook.createCellStyle() ).thenReturn( xlsStyle );

  when( styleKey.getHorizontalAlignment() ).thenReturn( HorizontalAlignment.CENTER );
  when( styleKey.getVerticalAlignment() ).thenReturn( VerticalAlignment.CENTER );
  when( styleKey.isWrapText() ).thenReturn( true );
  when( workbook.getFontAt( anyShort() ) ).thenReturn( font );
  when( styleKey.getIndention() ).thenReturn( (short) 15 );

  when( styleKey.getDataStyle() ).thenReturn( (short) -1 );

  builder.withElementStyle( mock( StyleSheet.class ), styleKey );

  verify( xlsStyle, times( 1 ) ).setAlignment( eq( HorizontalAlignment.CENTER ) );
  verify( xlsStyle, times( 1 ) ).setVerticalAlignment( eq( VerticalAlignment.CENTER ) );
  verify( xlsStyle, times( 1 ) ).setFont( any() );
  verify( xlsStyle, times( 1 ) ).setWrapText( eq( true ) );
  verify( xlsStyle, times( 1 ) ).setIndention( eq( (short) 15 ) );
  verify( xlsStyle, times( 0 ) ).setDataFormat( anyShort() );
}
 
Example #13
Source File: XLSXWriter.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * create a library of cell styles
 */
private static Map<String, CellStyle> createStyles(Workbook wb){
  Map<String, CellStyle> styles = new HashMap<>();

  CellStyle style;
  Font headerFont = wb.createFont();
  headerFont.setBold(true);
  style = createBorderedStyle(wb);
  style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
  style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  style.setVerticalAlignment(VerticalAlignment.TOP);
  style.setWrapText(true);
  style.setFont(headerFont);
  styles.put("header", style);

  style = createBorderedStyle(wb);
  style.setVerticalAlignment(VerticalAlignment.TOP);
  style.setWrapText(true);    
  styles.put("body", style);

  return styles;
}
 
Example #14
Source File: XLSXWriter.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * create a library of cell styles
 */
private static Map<String, CellStyle> createStyles(Workbook wb){
  Map<String, CellStyle> styles = new HashMap<>();

  CellStyle style;
  Font headerFont = wb.createFont();
  headerFont.setBold(true);
  style = createBorderedStyle(wb);
  style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
  style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  style.setVerticalAlignment(VerticalAlignment.TOP);
  style.setWrapText(true);
  style.setFont(headerFont);
  styles.put("header", style);

  style = createBorderedStyle(wb);
  style.setVerticalAlignment(VerticalAlignment.TOP);
  style.setWrapText(true);    
  styles.put("body", style);

  return styles;
}
 
Example #15
Source File: AbstractSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
public static CellStyle createHeaderStyle(Workbook wb) {
	CellStyle headerStyle = wb.createCellStyle();
	headerStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
	headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	Font headerFont = wb.createFont();
	headerFont.setFontName("Arial");
	headerFont.setFontHeight(FONT_SIZE);
	headerFont.setBold(true);
	headerStyle.setFont(headerFont);
	headerStyle.setAlignment(HorizontalAlignment.CENTER);
	headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	headerStyle.setWrapText(true);
	return headerStyle;
}
 
Example #16
Source File: AbstractSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * create the styles in the workbook
 */
private void createStyles(Workbook wb) {
	// create the styles
	this.checkboxStyle = wb.createCellStyle();
	this.checkboxStyle.setAlignment(HorizontalAlignment.CENTER);
	this.checkboxStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	this.checkboxStyle.setBorderBottom(BorderStyle.THIN);
	this.checkboxStyle.setBorderLeft(BorderStyle.THIN);
	this.checkboxStyle.setBorderRight(BorderStyle.THIN);
	this.checkboxStyle.setBorderTop(BorderStyle.THIN);
	Font checkboxFont = wb.createFont();
	checkboxFont.setFontHeight(FONT_SIZE);
	checkboxFont.setFontName(CHECKBOX_FONT_NAME);
	this.checkboxStyle.setFont(checkboxFont);
	
	this.dateStyle = wb.createCellStyle();
	DataFormat df = wb.createDataFormat();
	this.dateStyle.setDataFormat(df.getFormat("m/d/yy h:mm"));
	
	this.greenWrapped = createLeftWrapStyle(wb);
	this.greenWrapped.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
	this.greenWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	this.greenWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	
	this.yellowWrapped = createLeftWrapStyle(wb);
	this.yellowWrapped.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
	this.yellowWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	
	this.redWrapped = createLeftWrapStyle(wb);
	this.redWrapped.setFillForegroundColor(HSSFColor.RED.index);
	this.redWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}
 
Example #17
Source File: AbstractSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
public static CellStyle createLeftWrapStyle(Workbook wb) {
	CellStyle wrapStyle = wb.createCellStyle();
	wrapStyle.setWrapText(true);
	wrapStyle.setAlignment(HorizontalAlignment.LEFT);
	wrapStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	return wrapStyle;
}
 
Example #18
Source File: CellStyleProxy.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
/**
 * 縦位置を設定する
 * @param align 縦位置
 */
public void setVerticalAlignment(final VerticalAlignment align) {

    if(cell.getCellStyle().getVerticalAlignmentEnum().equals(align)) {
        // 既に縦位置が同じ値
        return;
    }

    cloneStyle();
    cell.getCellStyle().setVerticalAlignment(align);
}
 
Example #19
Source File: HSSFCellStyleProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Converts the given element alignment into one of the VerticalAlignment-constants.
 *
 * @param e the JFreeReport element alignment.
 * @return the VerticalAlignment-Alignment.
 * @throws IllegalArgumentException if an Unknown JFreeReport alignment is given.
 */
protected static VerticalAlignment convertVerticalAlignment( final ElementAlignment e ) {
  if ( ElementAlignment.TOP.equals( e ) ) {
    return VerticalAlignment.TOP;
  } else if ( ElementAlignment.BOTTOM.equals( e ) ) {
    return VerticalAlignment.BOTTOM;
  } else if ( ElementAlignment.MIDDLE.equals( e ) ) {
    return VerticalAlignment.CENTER;
  }

  throw new IllegalArgumentException( "Invalid alignment" );
}
 
Example #20
Source File: ExcelCellStyleBuilderTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testNullElementSttle() {
  ExcelCellStyleBuilder builder = new ExcelCellStyleBuilder( workbook );

  when( workbook.createCellStyle() ).thenReturn( xlsStyle );
  builder.withElementStyle( null, styleKey );

  verify( xlsStyle, times( 0 ) ).setAlignment( any( HorizontalAlignment.class ) );
  verify( xlsStyle, times( 0 ) ).setVerticalAlignment( any( VerticalAlignment.class ) );
  verify( xlsStyle, times( 0 ) ).setFont( any() );
  verify( xlsStyle, times( 0 ) ).setWrapText( anyBoolean() );
  verify( xlsStyle, times( 0 ) ).setIndention( anyShort() );
  verify( xlsStyle, times( 0 ) ).setDataFormat( anyShort() );
}
 
Example #21
Source File: JRXlsExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HSSFCellStyle getLoadedCellStyle(
	FillPatternType mode,
	short backcolor,
	HorizontalAlignment horizontalAlignment,
	VerticalAlignment verticalAlignment,
	short rotation,
	HSSFFont font,
	JRExporterGridCell gridCell,
	boolean isWrapText,
	boolean isCellLocked,
	boolean isCellHidden,
	boolean isShrinkToFit
	)
{
	return getLoadedCellStyle(
		new StyleInfo(
			mode, 
			backcolor, 
			horizontalAlignment, 
			verticalAlignment, 
			rotation, 
			font, 
			gridCell, 
			isWrapText, 
			isCellLocked, 
			isCellHidden, 
			isShrinkToFit));
}
 
Example #22
Source File: SpreadsheetCellStyleTest.java    From taro with MIT License 5 votes vote down vote up
@Test
public void SpreadsheetCellStyle_IsImmutable() {
    SpreadsheetCellStyle cellStyle = new SpreadsheetCellStyle();
    assertThat(cellStyle.withBold(true), is(not(cellStyle)));
    assertThat(cellStyle.withDoubleUnderline(true), is(not(cellStyle)));
    assertThat(cellStyle.withFontName("Courier"), is(not(cellStyle)));
    assertThat(cellStyle.withFontOffset(1), is(not(cellStyle)));
    assertThat(cellStyle.withFontSizeInPoints(14), is(not(cellStyle)));
    assertThat(cellStyle.withItalic(true), is(not(cellStyle)));
    assertThat(cellStyle.withStrikeout(true), is(not(cellStyle)));
    assertThat(cellStyle.withUnderline(true), is(not(cellStyle)));

    assertThat(cellStyle.withAlign(HorizontalAlignment.CENTER), is(not(cellStyle)));
    assertThat(cellStyle.withBackgroundColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withBottomBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withBottomBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withLeftBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withLeftBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withTopBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withTopBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withRightBorder(BorderStyle.MEDIUM), is(not(cellStyle)));
    assertThat(cellStyle.withRightBorderColor(Color.BLUE), is(not(cellStyle)));
    assertThat(cellStyle.withDataFormatString("0.00"), is(not(cellStyle)));
    assertThat(cellStyle.withIndention(1), is(not(cellStyle)));
    assertThat(cellStyle.withLocked(true), is(not(cellStyle)));
    assertThat(cellStyle.withRotation(1), is(not(cellStyle)));
    assertThat(cellStyle.withVerticalAlign(VerticalAlignment.TOP), is(not(cellStyle)));
    assertThat(cellStyle.withWrapText(true), is(not(cellStyle)));

    assertThat(cellStyle.copy(), not(sameInstance(cellStyle)));
    assertThat(cellStyle.apply(new SpreadsheetCellStyle()), not(sameInstance(cellStyle)));
}
 
Example #23
Source File: ExportTimetableXLS.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected CellStyle getMeetingFooterStyle(P p, P parent, Color bgColor) {
	if (bgColor == null) bgColor = Color.WHITE;
	String styleId = "meeting-footer-" + Integer.toHexString(bgColor.getRGB());
	CellStyle style = iStyles.get(styleId);
	if (style == null) {
		style = iWorkbook.createCellStyle();
        style.setBorderBottom(BorderStyle.THICK);
        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderLeft(BorderStyle.THICK);
        style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderRight(BorderStyle.THICK);
        style.setRightBorderColor(IndexedColors.BLACK.getIndex());
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.TOP);
        style.setFont(getFont(parent));
        String colorId = Integer.toHexString(bgColor.getRGB());
		Short color = iColors.get(colorId);
		if (color == null) {
			HSSFPalette palette = ((HSSFWorkbook)iWorkbook).getCustomPalette();
			HSSFColor clr = palette.findSimilarColor(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue());
			color = (clr == null ? IndexedColors.WHITE.getIndex() : clr.getIndex());
			iColors.put(colorId, color);
		}
        style.setFillForegroundColor(color);
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style.setWrapText(true);
        iStyles.put(styleId, style);
	}
	return style;
}
 
Example #24
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public StyleInfo(
	FillPatternType mode,
	short backcolor,
	HorizontalAlignment horizontalAlignment,
	VerticalAlignment verticalAlignment,
	short rotation,
	HSSFFont font,
	BoxStyle box,
	boolean wrapText,
	boolean cellLocked,
	boolean cellHidden,
	boolean shrinkToFit
	) 
{
	this.mode = mode;
	this.backcolor = backcolor;
	this.horizontalAlignment = horizontalAlignment;
	this.verticalAlignment = verticalAlignment;
	this.rotation = rotation;
	this.font = font;
	
	this.box = box;
	this.lcWrapText = shrinkToFit ? false : wrapText;
	this.lcCellLocked = cellLocked;
	this.lcCellHidden = cellHidden;
	this.lcShrinkToFit = shrinkToFit;
	hashCode = computeHash();
}
 
Example #25
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
private VerticalAlignment getVerticalAlignment(TextAlignHolder alignment) {
	switch (alignment.verticalAlignment) {
		case BOTTOM:
			return VerticalAlignment.BOTTOM;
		case MIDDLE:
			return VerticalAlignment.CENTER;
		case JUSTIFIED:
			return VerticalAlignment.JUSTIFY;
		case TOP:
		default:
			return VerticalAlignment.TOP;
	}
}
 
Example #26
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HSSFCellStyle getLoadedCellStyle(
	FillPatternType mode,
	short backcolor,
	HorizontalAlignment horizontalAlignment,
	VerticalAlignment verticalAlignment,
	short rotation,
	HSSFFont font,
	BoxStyle box,
	boolean isCellLocked,
	boolean isCellHidden,
	boolean isShrinkToFit
	) 
{
	return getLoadedCellStyle(new StyleInfo(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, box, true, isCellLocked, isCellHidden, isShrinkToFit));
}
 
Example #27
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void exportRectangle(JRPrintGraphicElement element) throws JRException {
	String currentColumnName = element.getPropertiesMap().getProperty(JRXlsAbstractMetadataExporter.PROPERTY_COLUMN_NAME);
	
	if (currentColumnName != null && currentColumnName.length() > 0) {
		boolean repeatValue = getPropertiesUtil().getBooleanProperty(element, JRXlsAbstractMetadataExporter.PROPERTY_REPEAT_VALUE, false);
		
		setColumnName(currentColumnName);
		adjustColumnWidth(currentColumnName, element.getWidth(), ((JRXlsExporterNature)nature).getColumnAutoFit(element));
		adjustRowHeight(element.getHeight(), ((JRXlsExporterNature)nature).getRowAutoFit(element));
		
		short forecolor = getWorkbookColor(element.getLinePen().getLineColor()).getIndex();

		FillPatternType mode = backgroundMode;
		short backcolor = whiteIndex;
		if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && element.getBackcolor() != null) {
			mode = FillPatternType.SOLID_FOREGROUND;
			backcolor = getWorkbookColor(element.getBackcolor()).getIndex();
		}

		HSSFCellStyle cellStyle =
			getLoadedCellStyle(
				mode,
				backcolor,
				HorizontalAlignment.LEFT,
				VerticalAlignment.TOP,
				(short)0,
				getLoadedFont(getDefaultFont(), forecolor, null, getLocale()),
				new BoxStyle(element),
				isCellLocked(element),
				isCellHidden(element),
				isShrinkToFit(element)
				);
		addBlankElement(cellStyle, repeatValue, currentColumnName);
	}
}
 
Example #28
Source File: JRXlsExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public StyleInfo(
	FillPatternType mode,
	short backcolor,
	HorizontalAlignment horizontalAlignment,
	VerticalAlignment verticalAlignment,
	short rotation,
	HSSFFont font,
	BoxStyle box,
	boolean wrapText,
	boolean cellLocked,
	boolean cellHidden,
	boolean shrinkToFit
	)
{
	this.mode = mode;
	this.backcolor = backcolor;
	this.horizontalAlignment = horizontalAlignment;
	this.verticalAlignment = verticalAlignment;
	this.rotation = rotation;
	this.font = font;
		
	this.box = box;
	this.lcWrapText = shrinkToFit ? false : wrapText;
	this.lcCellLocked = cellLocked;
	this.lcCellHidden = cellHidden;
	this.lcShrinkToFit = shrinkToFit;
	hashCode = computeHash();
}
 
Example #29
Source File: ExcelUtil.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 创建表格样式
 * 
 * @param wb 工作薄对象
 * @return 样式列表
 */
private Map<String, CellStyle> createStyles(Workbook wb)
{
    // 写入各条记录,每条记录对应excel表中的一行
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.THIN);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    Font dataFont = wb.createFont();
    dataFont.setFontName("Arial");
    dataFont.setFontHeightInPoints((short) 10);
    style.setFont(dataFont);
    styles.put("data", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    Font headerFont = wb.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setBold(true);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(headerFont);
    styles.put("header", style);

    return styles;
}
 
Example #30
Source File: JRXlsExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void exportFrame(JRPrintFrame frame, JRExporterGridCell gridCell, int x, int y)
{
	FillPatternType mode = backgroundMode;
	short backcolor = whiteIndex;
	if (frame.getModeValue() == ModeEnum.OPAQUE)
	{
		mode = FillPatternType.SOLID_FOREGROUND;
		backcolor = getWorkbookColor(frame.getBackcolor()).getIndex();
	}

	short forecolor = getWorkbookColor(frame.getForecolor()).getIndex();

	HSSFCellStyle cellStyle =
		getLoadedCellStyle(
			mode,
			backcolor,
			HorizontalAlignment.LEFT,
			VerticalAlignment.TOP,
			(short)0,
			getLoadedFont(getDefaultFont(), forecolor, null, getLocale()),
			gridCell,
			isWrapText(frame),
			isCellLocked(frame),
			isCellHidden(frame),
			isShrinkToFit(frame)
			);

	createMergeRegion(gridCell, x, y, cellStyle);

	cell = row.createCell(x);
	cell.setCellStyle(cellStyle);
}