当前位置: 首页>>代码示例>>Java>>正文


Java XSSFFont类代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFFont的典型用法代码示例。如果您正苦于以下问题:Java XSSFFont类的具体用法?Java XSSFFont怎么用?Java XSSFFont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XSSFFont类属于org.apache.poi.xssf.usermodel包,在下文中一共展示了XSSFFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createColorXSSFFont

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * @param wb
 * @param fontFamily
 * @param height
 * @param color
 * @param bold
 * @return
 */
public static XSSFFont createColorXSSFFont(XSSFWorkbook wb,String fontFamily,short height,XSSFColor color,boolean bold){
	String message="XSSFWorkbook must not be null!";
	Objects.requireNonNull(wb, () -> message);
	XSSFFont cellfont=wb.createFont();
	cellfont.setFontName(fontFamily);
	cellfont.setFontHeightInPoints(height);
	cellfont.setColor(color);
	if(bold){
		cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
	}
	return cellfont;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:21,代码来源:XSSFontUtil.java

示例2: configFont

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
private void configFont(Font font) {
    font.setBold(isBold());
    font.setItalic(isItalic());
    font.setStrikeout(isStrikeout());
    font.setUnderline(isUnderline() ? Font.U_SINGLE : Font.U_NONE);
    if (getFontSize() != null) {
        font.setFontHeightInPoints(fontSize.shortValue());
    }
    if (getFontColor() != null) {
        if (font instanceof XSSFFont) {
            ((XSSFFont)font).setColor(new XSSFColor(toRgbByte(fontColor)));
        } else {
            font.setColor(fontColor.getIndex());
        }
    }
}
 
开发者ID:tecsinapse,项目名称:tecsinapse-data-io,代码行数:17,代码来源:TableCellStyle.java

示例3: createPoiFont

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
private static org.apache.poi.ss.usermodel.Font createPoiFont(PoiWorkbook workbook, Font other) {
    org.apache.poi.ss.usermodel.Font poiFont = workbook.getPoiWorkbook().createFont();
    poiFont.setFontHeightInPoints((short) Math.round(other.getSizeInPoints()));
    poiFont.setFontName(other.getFamily());

    final org.apache.poi.ss.usermodel.Color poiTextColor = workbook.getPoiColor(other.getColor());
    if (poiFont instanceof HSSFFont && poiTextColor instanceof HSSFColor) {
        poiFont.setColor(((HSSFColor) poiTextColor).getIndex());
    } else if (poiFont instanceof XSSFFont && poiTextColor instanceof XSSFColor) {
        ((XSSFFont) poiFont).setColor((XSSFColor) poiTextColor);
    } else {
        // it should both either be XSSF _or_ HSSF implementations so this
        // line should never be reached.
        throw new IllegalStateException();
    }

    poiFont.setBold(other.isBold());
    poiFont.setItalic(other.isItalic());
    poiFont.setStrikeout(other.isStrikeThrough());
    poiFont.setUnderline(other.isUnderlined() ? org.apache.poi.ss.usermodel.Font.U_SINGLE
            : org.apache.poi.ss.usermodel.Font.U_NONE);

    return poiFont;
}
 
开发者ID:xzel23,项目名称:meja,代码行数:25,代码来源:PoiFont.java

示例4: addLangCell

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
private int addLangCell(Row header, TmxSegement segment) {
	int CellNum = header.getLastCellNum();
	if (-1 == CellNum) {
		CellNum = 0;
	}
	Cell createCell = header.createCell(CellNum);
	CellStyle cellStyle = wb.createCellStyle();
	XSSFFont headerFont = (XSSFFont) wb.createFont();
	headerFont.setBold(true);
	cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
	cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
	cellStyle.setFont(headerFont);
	createCell.setCellValue(segment.getLangCode());
	createCell.setCellStyle(cellStyle);
	sh.setColumnWidth(CellNum, (100 * 7 + 5) / 7 * 256);
	return CellNum;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:18,代码来源:Excel2007Writer.java

示例5: addColourToFont

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
@Override
public void addColourToFont(Workbook workbook, Font font, String colour) {
	if(colour == null) {
		return ;
	}
	if(IStyle.TRANSPARENT_VALUE.equals(colour)) {
		return ;
	}
	if(font instanceof XSSFFont) {
		XSSFFont xFont = (XSSFFont)font;
		XSSFColor xColour = getXColour(colour);
		
		if(xColour != null) {
			xFont.setColor(xColour);
		}
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:18,代码来源:StyleManagerXUtils.java

示例6: correctFontColorIfBackground

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:24,代码来源:StyleManagerXUtils.java

示例7: styleHeader

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * See http://thinktibits.blogspot.co.uk/2012/12/Java-POI-XLS-XLSX-Change-Cell-Font-Color-Example.html
 * Currently only for xlsx
 * @param wb
 * @param sheet
 */
private static void styleHeader(Workbook wb, Sheet sheet){
	if(XSSFWorkbook.class.isInstance(wb) && XSSFSheet.class.isInstance(sheet)){
        XSSFWorkbook my_workbook = (XSSFWorkbook)wb; 
        XSSFCellStyle my_style = my_workbook.createCellStyle();
        XSSFFont my_font=my_workbook.createFont();
        my_font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        my_style.setFont(my_font);
        
        Row row = sheet.getRow(0);
        if(row!=null && row.getFirstCellNum()>=0){
	        for(int i = row.getFirstCellNum() ; i<= row.getLastCellNum();i++){
	        	Cell cell = row.getCell(i);
	        	if(cell!=null){
		        	cell.setCellStyle(my_style);	        		
	        	}
	        }	        	
        }
	}        
}
 
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:26,代码来源:PoiIO.java

示例8: getRepresentation

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * Gets the string representation of the given <code>Font</code>.
 * @param f A <code>Font</code>.
 * @return The string representation.
 */
private String getRepresentation(Font f)
{
   // Colors that need an instanceof check
   Color fontColor;
   if (f instanceof HSSFFont)
   {
      HSSFFont hf = (HSSFFont) f;
      fontColor = hf.getHSSFColor((HSSFWorkbook) myWorkbook);
   }
   else if (f instanceof XSSFFont)
   {
      XSSFFont xf = (XSSFFont) f;
      fontColor = xf.getXSSFColor();
   }
   else
      throw new IllegalArgumentException("Bad Font type: " + f.getClass().getName());

   return getRepresentation(f.getBoldweight(), f.getItalic(), fontColor, f.getFontName(),
      f.getFontHeightInPoints(), f.getUnderline(), f.getStrikeout(), f.getCharSet(), f.getTypeOffset());
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:26,代码来源:FontCache.java

示例9: findFont

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
private static Font findFont(Workbook workbook, Font font)
{
   int numFonts = workbook.getNumberOfFonts();
   for (short i = 0; i < numFonts; i++)
   {
      Font f = workbook.getFontAt(i);
      if (f.getBoldweight() == font.getBoldweight() &&
          f.getItalic() == font.getItalic() &&
          f.getColor() == font.getColor() &&
          f.getFontHeight() == font.getFontHeight() &&
          f.getUnderline() == font.getUnderline() &&
          f.getFontName().equals(font.getFontName()) &&
          f.getTypeOffset() == font.getTypeOffset()
         )
      {
         if (!(font instanceof XSSFFont && f instanceof XSSFFont) ||
             ((XSSFFont) font).getXSSFColor().getARGBHex().equals(((XSSFFont) f).getXSSFColor().getARGBHex()))
         {
            if (DEBUG)
               System.err.println("    Found existing, matching Font!");
            return f;
         }
      }
   }
   if (DEBUG)
      System.err.println("    Did NOT find existing, matching Font!");
   return null;
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:29,代码来源:RichTextStringUtil.java

示例10: XLSXTranslatorOutputFormat

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * Public constructor.
 * @param os output stream
 */
public XLSXTranslatorOutputFormat(final OutputStream os) {

  if (os == null) {
    throw new NullPointerException("The output stream is null");
  }

  this.os = os;

  // Temporary files will be compressed
  this.wb.setCompressTempFiles(true);

  // Define default style
  Font defaultFont = this.wb.createFont();
  defaultFont.setFontName("Arial");
  defaultFont.setFontHeightInPoints((short) 10);
  this.defaultStyle = this.wb.createCellStyle();
  this.defaultStyle.setFont(defaultFont);

  // Define header style
  Font headerFont = this.wb.createFont();
  headerFont.setFontName(defaultFont.getFontName());
  headerFont.setFontHeightInPoints(defaultFont.getFontHeightInPoints());
  headerFont.setItalic(true);
  this.headerStyle = this.wb.createCellStyle();
  this.headerStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
  this.headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  this.headerStyle.setFont(headerFont);

  // Define link style
  Font linkfont = this.wb.createFont();
  linkfont.setFontName(defaultFont.getFontName());
  linkfont.setFontHeightInPoints(defaultFont.getFontHeightInPoints());
  linkfont.setUnderline(XSSFFont.U_SINGLE);
  linkfont.setColor(IndexedColors.BLUE.getIndex());
  this.linkStyle = this.wb.createCellStyle();
  this.linkStyle.setFont(linkfont);
}
 
开发者ID:GenomicParisCentre,项目名称:eoulsan,代码行数:42,代码来源:XLSXTranslatorOutputFormat.java

示例11: createXSSFFont

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * @param wb
 * @return {code XSSFFont}
 */
public static XSSFFont createXSSFFont(XSSFWorkbook wb){
	String message="XSSFWorkbook must not be null!";
	Objects.requireNonNull(wb, () -> message);
	XSSFFont cellfont=wb.createFont();
	cellfont.setFontName("新宋体");
	cellfont.setFontHeightInPoints((short) 12);
	cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
	cellfont.setColor(new XSSFColor(new Color(50,73,38)));
	
	return cellfont;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:16,代码来源:XSSFontUtil.java

示例12: setCell

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * @param sheet 
 * @param pos 位置【row,col】
 * @param style
 * @param v
 */
public static void setCell(final XSSFWorkbook wb,final XSSFSheet sheet,int[] pos,CellStyle style,FontStyle font,String v){
	XSSFRow row = sheet.getRow(pos[0]);
	XSSFCell cell = CellValueUtil.createCellIfNotPresent(row, pos[1]);
	XSSFCellStyle _style = Objects
			.requireNonNull(new XSSFCellStyleLib(wb).get(style),
					"specified style not defined!");
	XSSFFont _font = Objects
			.requireNonNull(new XSSFFontStyleLib(wb).get(font),
					"specified font not defined!");
	_style.setFont(_font);
	setCellProperties(cell, v, _style);
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:19,代码来源:CellValueUtil.java

示例13: getCaptionCellStyle

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * 返回副标题字体样式
 * @param wb
 * @return
 */
public static XSSFCellStyle getCaptionCellStyle(XSSFWorkbook wb){
	//default cellStyle
	XSSFCellStyle cellStyle=createXSSFCellStyle(wb);
	//default font
	XSSFFont cellfont=XSSFontUtil.createXSSFFont(wb);
	cellStyle.setFont(cellfont);
	return cellStyle;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:14,代码来源:XSSFCellUtil.java

示例14: getcontentCellStyle

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
 * 返回excel内容字体样式
 * @param wb
 * @return
 */
public static XSSFCellStyle getcontentCellStyle(XSSFWorkbook wb){
	String message="XSSFWorkbook must not be null!";
	Objects.requireNonNull(wb, () -> message);
	XSSFCellStyle contentStyle=createCenterXSSFCellStyle(wb);
	//fill enlarged font
	XSSFFont enlargedFont=XSSFontUtil.createColorXSSFFont(wb, "新宋体", (short) 16, new XSSFColor(Color.WHITE), true);
	contentStyle.setFont(enlargedFont);
	return contentStyle;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:15,代码来源:XSSFCellUtil.java

示例15: get

import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
public  XSSFFont get(FontStyle k){
	XSSFFont v=FONT_STYLE_MAP.get(k);
	if(null==v){
		throw new FontStyleNotFoundException("the font style have not been defined!");
	}
	return v;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:8,代码来源:XSSFFontStyleLib.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFFont类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。