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

The following examples show how to use org.apache.poi.ss.usermodel.Font. 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: ExcelExportStylerColorImpl.java    From autopoi with Apache License 2.0 8 votes vote down vote up
@Override
public CellStyle getHeaderStyle(short headerColor) {
	CellStyle titleStyle = workbook.createCellStyle();
	Font font = workbook.createFont();
	font.setFontHeightInPoints((short) 24);
	titleStyle.setFont(font);
	titleStyle.setFillForegroundColor(headerColor);
	titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
	return titleStyle;
}
 
Example #2
Source File: ExcelExporterProcess.java    From youkefu with Apache License 2.0 8 votes vote down vote up
private CellStyle baseCellStyle(){
	CellStyle cellStyle = wb.createCellStyle();
	cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); 

	cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); 
			
	cellStyle.setWrapText(true);
	cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
	cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
	cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
	cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
	
	Font font = wb.createFont(); 
	font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); 
	//font.setFontName("宋体"); 
	font.setFontHeight((short) 200); 
	cellStyle.setFont(font); 
	
	return cellStyle;
}
 
Example #3
Source File: AbstractStyleBuilder.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
public void setCellStyleFont(Workbook workbook, CellStyle style, int i) {
	Font font = workbook.createFont();
	if (i == 0) {
		// 正常
	} else if (i == 4) {
		// 下划线
		font.setUnderline(Font.U_SINGLE);
		style.setFont(font);
	} else if (i == 2) {
		// 倾斜
		font.setItalic(true);
		style.setFont(font);
	} else if (i == 1) {
		// 加粗
		font.setBoldweight(Font.BOLDWEIGHT_BOLD);
		style.setFont(font);
	}
}
 
Example #4
Source File: ExportEventsImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
    final Font font = sheet.getWorkbook ().createFont ();
    font.setFontName ( "Arial" );
    font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
    font.setColor ( HSSFColor.WHITE.index );

    final CellStyle style = sheet.getWorkbook ().createCellStyle ();
    style.setFont ( font );
    style.setFillForegroundColor ( HSSFColor.BLACK.index );
    style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );

    final HSSFRow row = sheet.createRow ( 0 );

    for ( int i = 0; i < columns.size (); i++ )
    {
        final Field field = columns.get ( i );

        final HSSFCell cell = row.createCell ( i );
        cell.setCellValue ( field.getHeader () );
        cell.setCellStyle ( style );
    }
}
 
Example #5
Source File: XLSXResponseWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
SerialWriteWorkbook() {
  this.swb = new SXSSFWorkbook(100);
  this.sh = this.swb.createSheet();

  this.rowIndex = 0;

  this.headerStyle = (XSSFCellStyle)swb.createCellStyle();
  this.headerStyle.setFillBackgroundColor(IndexedColors.BLACK.getIndex());
  //solid fill
  this.headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  Font headerFont = swb.createFont();
  headerFont.setFontHeightInPoints((short)14);
  headerFont.setBold(true);
  headerFont.setColor(IndexedColors.WHITE.getIndex());
  this.headerStyle.setFont(headerFont);
}
 
Example #6
Source File: AbstractSheet.java    From tools with Apache License 2.0 6 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(CellStyle.ALIGN_CENTER);
	this.checkboxStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
	this.checkboxStyle.setBorderBottom(CellStyle.BORDER_THIN);
	this.checkboxStyle.setBorderLeft(CellStyle.BORDER_THIN);
	this.checkboxStyle.setBorderRight(CellStyle.BORDER_THIN);
	this.checkboxStyle.setBorderTop(CellStyle.BORDER_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"));
}
 
Example #7
Source File: RWorkbook.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
/**
 * 创建一个新的样式,样式从i_DataCell中克隆出来。
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-09-11
 * @version     v1.0
 *
 * @param i_ID         标记ID。由调用者设定
 * @param i_DataCell   被克隆的单元格样式
 * @return
 */
public synchronized CellStyle getCellStyleByCopy(String i_ID ,Cell i_DataCell ,RTemplate i_RTemplate)
{
    CellStyle v_NewCellStyle = this.cellStylesByCopy.get(i_ID);
    
    if ( v_NewCellStyle == null )
    {
        v_NewCellStyle = this.workbook.createCellStyle();
        
        ExcelHelp.copyCellStyle(i_DataCell.getCellStyle(), v_NewCellStyle);
        
        Font v_FromFont = this.workbook.getFontAt(i_DataCell.getCellStyle().getFontIndex());
        Font v_NewFont  = this.workbook.createFont();
        ExcelHelp.copyFont(v_FromFont ,v_NewFont);
        
        v_NewCellStyle.setFont(v_NewFont);
        
        this.cellStylesByCopy.put(i_ID ,v_NewCellStyle);
    }
    
    return v_NewCellStyle;
}
 
Example #8
Source File: FontManager.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get a Font matching the BIRT style, either from the cache or by creating a new one.
 * @param birtStyle
 * The BIRT style to base the Font upon.
 * @return
 * A Font whose attributes are described by the BIRT style. 
 */
public Font getFont( BirtStyle birtStyle ) {
	if( birtStyle == null ) {
		return getDefaultFont();
	}
	
	if( ( birtStyle.getProperty( StyleConstants.STYLE_FONT_FAMILY ) == null )
			&& ( birtStyle.getProperty( StyleConstants.STYLE_FONT_SIZE ) == null )
			&& ( birtStyle.getProperty( StyleConstants.STYLE_FONT_WEIGHT ) == null )
			&& ( birtStyle.getProperty( StyleConstants.STYLE_FONT_STYLE ) == null )
			&& ( birtStyle.getProperty( StyleConstants.STYLE_TEXT_UNDERLINE ) == null )
			&& ( birtStyle.getProperty( StyleConstants.STYLE_COLOR ) == null )
			) {
		return getDefaultFont();
	}
	
	for(FontPair fontPair : fonts) {
		if(fontsEquivalent(birtStyle, fontPair.birtStyle)) {
			return fontPair.poiFont;
		}
	}
	
	return createFont(birtStyle);
}
 
Example #9
Source File: StyleManagerXUtils.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Font correctFontColorIfBackground( FontManager fm, Workbook wb, BirtStyle birtStyle, Font font ) {
	CSSValue bgColour = birtStyle.getProperty( StyleConstants.STYLE_BACKGROUND_COLOR );
	int bgRgb[] = parseColour( bgColour == null ? null : bgColour.getCssText(), "white" );

	XSSFColor colour = ((XSSFFont)font).getXSSFColor();
	int fgRgb[] = rgbOnly( colour.getARgb() );
	if( ( fgRgb[0] == 255 ) && ( fgRgb[1] == 255 ) && ( fgRgb[2] == 255 ) ) {
		fgRgb[0]=fgRgb[1]=fgRgb[2]=0;
	} else if( ( fgRgb[0] == 0 ) && ( fgRgb[1] == 0 ) && ( fgRgb[2] == 0 ) ) {
		fgRgb[0]=fgRgb[1]=fgRgb[2]=255;
	}

	if( ( bgRgb[ 0 ] == fgRgb[ 0 ] ) && ( bgRgb[ 1 ] == fgRgb[ 1 ] ) && ( bgRgb[ 2 ] == fgRgb[ 2 ] ) ) {
		
		IStyle addedStyle = new AreaStyle( fm.getCssEngine() );
		addedStyle.setColor( contrastColour( bgRgb ) );
		
		return fm.getFontWithExtraStyle( font, addedStyle );
	} else {
		return font;
	}
}
 
Example #10
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 #11
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 #12
Source File: ExcelExporterProcess.java    From youkefu with Apache License 2.0 6 votes vote down vote up
/**
 * 首列样式
 * @return
 */
private CellStyle createFirstCellStyle(){
	CellStyle cellStyle = baseCellStyle();
	Font font = wb.createFont();
	//font.setFontName("微软雅黑"); 
	font.setFontHeight((short) 180);
	cellStyle.setFont(font);
	
	cellStyle.setWrapText(false);
	
	cellStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
	cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
	

	return cellStyle;
}
 
Example #13
Source File: ExcelExporterProcess.java    From youkefu with Apache License 2.0 6 votes vote down vote up
private CellStyle createContentStyle(){
	CellStyle cellStyle = wb.createCellStyle(); 
	
	cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 指定单元格居中对齐 
	cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 指定单元格垂直居中对齐 
	cellStyle.setWrapText(false);// 指定单元格自动换行 

	// 设置单元格字体 
	Font font = wb.createFont(); 
	//font.setFontName("微软雅黑"); 
	font.setFontHeight((short) 200); 
	cellStyle.setFont(font); 
	cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
	cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
	cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
	cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
	return cellStyle ;
}
 
Example #14
Source File: TitleStyleBuilder.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
private HSSFCellStyle createHSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
	HSSFWorkbook workbook = (HSSFWorkbook) wb;
	HSSFPalette palette = workbook.getCustomPalette();
	
	palette.setColorAtIndex((short) 9, (byte) fontColor[0], (byte) fontColor[1], (byte) fontColor[2]);
	palette.setColorAtIndex((short) 10, (byte) bgColor[0], (byte) bgColor[1], (byte) bgColor[2]);

	HSSFFont titleFont = workbook.createFont();
	titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
	titleFont.setFontName("宋体");
	titleFont.setColor((short) 9);
	titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
	titleFont.setFontHeightInPoints((short) fontSize);

	HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true);
	titleStyle.setFont(titleFont);
	titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
	titleStyle.setFillForegroundColor((short) 10);
	titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

	return titleStyle;
}
 
Example #15
Source File: RWorkbook.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
/**
 * 获取模板指定位置上的已转为本工作薄的字体
 * 
 * 目前看,只用于2003的版本(*.xls),2007的版本是可以直接 setFont() 方法设置字体的。
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-18
 * @version     v1.0
 *
 * @param i_RTemplate  模板对象
 * @param i_IDX        字体在模板中的索引位置
 * @return
 */
public synchronized Font getFont(RTemplate i_RTemplate ,int i_IDX)
{
    Font   v_FromFont = i_RTemplate.getTemplateSheet().getWorkbook().getFontAt((short)i_IDX);
    String v_FontID   = makeFontID(v_FromFont);
    Font   v_ToFont   = this.fonts.get(v_FontID);
    
    if ( v_ToFont == null )
    {
        v_ToFont = this.workbook.createFont();
        ExcelHelp.copyFont(v_FromFont ,v_ToFont);
        
        this.fonts.put(v_FontID ,v_ToFont);
    }
    
    return v_ToFont;
}
 
Example #16
Source File: StyleConfiguration.java    From excel-rw-annotation with Apache License 2.0 6 votes vote down vote up
/**
 * 设置通用的对齐居中、边框等
 *
 * @param style 样式
 */
private void setCommonStyle(CellStyle style) {
    // 设置单元格居中对齐、自动换行
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setWrapText(true);

    //设置单元格字体
    if (!buildInFontMap.containsKey(FONT_KEY)) {
        Font font = workbook.createFont();
        //通用字体
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font.setFontName("宋体");
        font.setFontHeight((short) 200);
        buildInFontMap.put(FONT_KEY, font);
    }
    style.setFont(buildInFontMap.get(FONT_KEY));

    // 设置单元格边框为细线条
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setBorderTop(CellStyle.BORDER_THIN);
}
 
Example #17
Source File: JU_FontReport.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
@Test
public void test_FontOne() throws IOException
{
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("sheet 01");
    Row row = sheet.createRow(1);
    Font font = wb.createFont();
    font.setBold(true);
    font.setColor((short) 13);
    font.setFontHeightInPoints((short) 24);
    font.setFontName("宋体");
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFont(font);
    Cell cell = row.createCell(1);
    cell.setCellValue("这是测试字体格式的");
    cell.setCellStyle(cellStyle);
    FileOutputStream fileOutputStream = new FileOutputStream("D://font.xlsx");
    wb.write(fileOutputStream);
    wb.close();
}
 
Example #18
Source File: ExcelExportUtil.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 表明的Style
 * @param workbook
 * @return
 */
public static HSSFCellStyle getHeaderStyle(HSSFWorkbook workbook, ExcelTitle entity) {
	HSSFCellStyle titleStyle = workbook.createCellStyle();
	Font font = workbook.createFont();
	font.setFontHeightInPoints((short) 24);
	titleStyle.setFont(font);
	titleStyle.setFillForegroundColor(entity.getColor()); 
	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
	return titleStyle;
}
 
Example #19
Source File: FontStyle.java    From myexcel with Apache License 2.0 5 votes vote down vote up
private static Font setFontColor(Font font, CustomColor customColor, String fontColor) {
    Short colorPredefined = ColorUtil.getPredefinedColorIndex(fontColor);
    if (colorPredefined != null) {
        font.setColor(colorPredefined);
        return font;
    }
    int[] rgb = ColorUtil.getRGBByColor(fontColor);
    if (rgb == null) {
        return null;
    }
    if (customColor.isXls()) {
        short index = ColorUtil.getCustomColorIndex(customColor, rgb);
        font.setColor(index);
    } else {
        ((XSSFFont) font).setColor(new XSSFColor(new Color(rgb[0], rgb[1], rgb[2]), customColor.getDefaultIndexedColorMap()));
    }
    return font;
}
 
Example #20
Source File: AbstractExcelFactory.java    From myexcel with Apache License 2.0 5 votes vote down vote up
private void doSetInnerSpan(Cell cell, Td td) {
    if (td.getFonts() == null || td.getFonts().isEmpty()) {
        return;
    }
    RichTextString richText = isHssf ? new HSSFRichTextString(td.getContent()) : new XSSFRichTextString(td.getContent());
    for (com.github.liaochong.myexcel.core.parser.Font font : td.getFonts()) {
        Font f = FontStyle.getFont(font.getStyle(), fontMap, () -> workbook.createFont(), customColor);
        richText.applyFont(font.getStartIndex(), font.getEndIndex(), f);
    }
    cell.setCellValue(richText);
}
 
Example #21
Source File: XLSPrinter.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected Font getFont(boolean bold, boolean italic, boolean underline, Color c) {
	Short color = null;
	if (c == null) c = Color.BLACK;
	if (c != null) {
		String colorId = Integer.toHexString(c.getRGB());
		color = iColors.get(colorId);
		if (color == null) {
			HSSFPalette palette = ((HSSFWorkbook)iWorkbook).getCustomPalette();
			HSSFColor clr = palette.findSimilarColor(c.getRed(), c.getGreen(), c.getBlue());
			color = (clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndex());
			iColors.put(colorId, color);
		}
	}
	String fontId = (bold ? "b" : "") + (italic ? "i" : "") + (underline ? "u" : "") + (color == null ? "" : color);
	Font font = iFonts.get(fontId);
	if (font == null) {
		font = iWorkbook.createFont();
		font.setBold(bold);
		font.setItalic(italic);
		font.setUnderline(underline ? Font.U_SINGLE : Font.U_NONE);
		font.setColor(color);
		font.setFontHeightInPoints((short)10);
		font.setFontName("Arial");
		iFonts.put(fontId, font);
	}
	return font;
}
 
Example #22
Source File: StylerHelper.java    From easypoi with Apache License 2.0 5 votes vote down vote up
private Color getColor(Font font) {
    if (helper instanceof HSSFHtmlHelper) {
        return ((HSSFWorkbook) sheet.getWorkbook()).getCustomPalette()
            .getColor(font.getColor());
    } else {
        return ((XSSFFont) font).getXSSFColor();
    }
}
 
Example #23
Source File: SheetUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Copy text attributes from the supplied Font to Java2D AttributedString
 */
private static void copyAttributes(Font font, AttributedString str, @SuppressWarnings("SameParameterValue") int startIdx, int endIdx) {
    str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx);
    str.addAttribute(TextAttribute.SIZE, (float)font.getFontHeightInPoints());
    if (font.getBold()) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx);
    if (font.getItalic() ) str.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIdx, endIdx);
    if (font.getUnderline() == Font.U_SINGLE ) str.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIdx, endIdx);
}
 
Example #24
Source File: ExcelFontFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructor for ExcelFontFactory.
 *
 * @param workbook
 *          the workbook.
 */
public ExcelFontFactory( final Workbook workbook, final ExcelColorProducer colorProducer ) {
  if ( workbook == null ) {
    throw new NullPointerException();
  }
  if ( colorProducer == null ) {
    throw new NullPointerException();
  }

  this.fonts = new HashMap<HSSFFontWrapper, Font>();
  this.workbook = workbook;

  // read the fonts from the workbook ...
  // Funny one: Please note that the layout will be broken if the first
  // font is not 'Arial 10'.
  final short numberOfFonts = this.workbook.getNumberOfFonts();
  for ( int i = 0; i < numberOfFonts; i++ ) {
    final Font font = workbook.getFontAt( (short) i );
    this.fonts.put( new HSSFFontWrapper( font ), font );
  }

  // add the default font
  // this MUST be the first one, that is created.
  // oh, I hate Excel ...
  final HSSFFontWrapper wrapper =
      new HSSFFontWrapper( "Arial", (short) 10, false, false, false, false, colorProducer
          .getNearestColor( Color.black ) );
  getExcelFont( wrapper );
}
 
Example #25
Source File: DefaultXlsTableExporter.java    From olat with Apache License 2.0 5 votes vote down vote up
private CellStyle getHeaderCellStyle(final Workbook wb) {
    CellStyle cellStyle = wb.createCellStyle();
    Font boldFont = wb.createFont();
    boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(boldFont);
    return cellStyle;
}
 
Example #26
Source File: CrosstabXLSExporter.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public CellStyle buildDimensionCellStyle(Sheet sheet) {
	CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
	cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
	cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);

	String headerBGColor = (String) this.getProperty(PROPERTY_DIMENSION_NAME_BACKGROUND_COLOR);
	logger.debug("Header background color : " + headerBGColor);
	short backgroundColorIndex = headerBGColor != null ? IndexedColors.valueOf(headerBGColor).getIndex() : IndexedColors.valueOf(
			DEFAULT_DIMENSION_NAME_BACKGROUND_COLOR).getIndex();
	cellStyle.setFillForegroundColor(backgroundColorIndex);

	cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

	cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
	cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
	cellStyle.setBorderRight(CellStyle.BORDER_THIN);
	cellStyle.setBorderTop(CellStyle.BORDER_THIN);

	String bordeBorderColor = (String) this.getProperty(PROPERTY_HEADER_BORDER_COLOR);
	logger.debug("Header border color : " + bordeBorderColor);
	short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex() : IndexedColors.valueOf(
			DEFAULT_HEADER_BORDER_COLOR).getIndex();

	cellStyle.setLeftBorderColor(borderColorIndex);
	cellStyle.setRightBorderColor(borderColorIndex);
	cellStyle.setBottomBorderColor(borderColorIndex);
	cellStyle.setTopBorderColor(borderColorIndex);

	Font font = sheet.getWorkbook().createFont();

	Short headerFontSize = (Short) this.getProperty(PROPERTY_HEADER_FONT_SIZE);
	logger.debug("Header font size : " + headerFontSize);
	short headerFontSizeShort = headerFontSize != null ? headerFontSize.shortValue() : DEFAULT_HEADER_FONT_SIZE;
	font.setFontHeightInPoints(headerFontSizeShort);

	String fontName = (String) this.getProperty(PROPERTY_FONT_NAME);
	logger.debug("Font name : " + fontName);
	fontName = fontName != null ? fontName : DEFAULT_FONT_NAME;
	font.setFontName(fontName);

	String color = (String) this.getProperty(PROPERTY_DIMENSION_NAME_COLOR);
	logger.debug("Dimension color : " + color);
	short colorIndex = bordeBorderColor != null ? IndexedColors.valueOf(color).getIndex() : IndexedColors.valueOf(DEFAULT_DIMENSION_NAME_COLOR).getIndex();
	font.setColor(colorIndex);

	font.setBoldweight(Font.BOLDWEIGHT_BOLD);
	font.setItalic(true);
	cellStyle.setFont(font);
	return cellStyle;
}
 
Example #27
Source File: SpreadsheetExporter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private CellStyle createHeaderStyle(){
    //TO-DO read style information from sakai.properties
    Font font = gradesWorkbook.createFont();
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setColor(IndexedColors.PLUM.getIndex());
    font.setBold(true);
    CellStyle cellStyle = gradesWorkbook.createCellStyle();
    cellStyle.setFont(font);
    return cellStyle;
}
 
Example #28
Source File: ExcelExportStylerColorImpl.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
@Override
public CellStyle getHeaderStyle(short headerColor) {
	CellStyle titleStyle = workbook.createCellStyle();
	Font font = workbook.createFont();
	font.setFontHeightInPoints((short) 24);
	titleStyle.setFont(font);
	titleStyle.setFillForegroundColor(headerColor);
	titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
	return titleStyle;
}
 
Example #29
Source File: ExcelExportStylerBorderImpl.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
@Override
public CellStyle getHeaderStyle(short color) {
	CellStyle titleStyle = workbook.createCellStyle();
	Font font = workbook.createFont();
	font.setFontHeightInPoints((short) 12);
	titleStyle.setFont(font);
	titleStyle.setBorderLeft((short) 1); // 左边框
	titleStyle.setBorderRight((short) 1); // 右边框
	titleStyle.setBorderBottom((short) 1);
	titleStyle.setBorderTop((short) 1);
	titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
	return titleStyle;
}
 
Example #30
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(CellStyle.SOLID_FOREGROUND);
	Font headerFont = wb.createFont();
	headerFont.setFontName("Arial");
	headerFont.setFontHeight(FONT_SIZE);
	headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
	headerStyle.setFont(headerFont);
	headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
	return headerStyle;
}