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


Java HSSFFont类代码示例

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


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

示例1: createHSSFCellStyle

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
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.setBold(true); 
	titleFont.setFontHeightInPoints((short) fontSize);

	HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true);
	titleStyle.setFont(titleFont);
	titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	titleStyle.setFillForegroundColor((short) 10);
	titleStyle.setAlignment(HorizontalAlignment.CENTER);
	titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);

	return titleStyle;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:24,代码来源:TitleStyleBuilder.java

示例2: createColumnHeaders

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
/**
 */
protected void createColumnHeaders() {
	final HSSFRow headersRow = this.sheet.createRow(0);
	final HSSFFont font = this.workbook.createFont();
	font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
	final HSSFCellStyle style = this.workbook.createCellStyle();
	style.setFont(font);
	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	int counter = 1;
	for (int i = 0; i < this.model.getColumnCount(); i++) {
		final HSSFCell cell = headersRow.createCell(counter++);
		// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue(this.model.getColumnName(i));
		cell.setCellStyle(style);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:18,代码来源:JKExcelUtil.java

示例3: getRichTextString

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
protected HSSFRichTextString getRichTextString(JRStyledText styledText, short forecolor, JRFont defaultFont, Locale locale)
{
	String text = styledText.getText();
	HSSFRichTextString richTextStr = new HSSFRichTextString(text);
	int runLimit = 0;
	AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();

	while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length())
	{
		Map<Attribute,Object> attributes = iterator.getAttributes();
		JRFont runFont = attributes.isEmpty()? defaultFont : new JRBaseFont(attributes);
		short runForecolor = attributes.get(TextAttribute.FOREGROUND) != null ? 
				getWorkbookColor((Color)attributes.get(TextAttribute.FOREGROUND)).getIndex() :
				forecolor;
		HSSFFont font = getLoadedFont(runFont, runForecolor, attributes, locale);
		richTextStr.applyFont(iterator.getIndex(), runLimit, font);
		iterator.setIndex(runLimit);
	}
	return richTextStr;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:21,代码来源:JRXlsExporter.java

示例4: getLoadedCellStyle

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
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);
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:18,代码来源:JRXlsExporter.java

示例5: StyleInfo

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
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);
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:27,代码来源:JRXlsExporter.java

示例6: getRichTextString

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
protected HSSFRichTextString getRichTextString(JRStyledText styledText, short forecolor, JRFont defaultFont, Locale locale) {
	String text = styledText.getText();
	HSSFRichTextString richTextStr = new HSSFRichTextString(text);
	int runLimit = 0;
	AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();

	while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length()) {
		Map<Attribute,Object> attributes = iterator.getAttributes();
		JRFont runFont = attributes.isEmpty()? defaultFont : new JRBaseFont(attributes);
		short runForecolor = attributes.get(TextAttribute.FOREGROUND) != null  
			? getWorkbookColor((Color)attributes.get(TextAttribute.FOREGROUND)).getIndex() 
			: forecolor;
		HSSFFont font = getLoadedFont(runFont, runForecolor, attributes, locale);
		richTextStr.applyFont(iterator.getIndex(), runLimit, font);
		iterator.setIndex(runLimit);
	}
	return richTextStr;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:19,代码来源:JRXlsMetadataExporter.java

示例7: copyFont

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
public static HSSFFont copyFont(final HSSFWorkbook workbook, final HSSFFont font) {

        final HSSFFont newFont = workbook.createFont();

        // newFont.setBoldweight(font.getBoldweight());
        // newFont.setCharSet(font.getCharSet());
        // newFont.setColor(font.getColor());
        // newFont.setFontHeight(font.getFontHeight());
        // newFont.setFontHeightInPoints(font.getFontHeightInPoints());
        // newFont.setFontName(font.getFontName());
        // newFont.setItalic(font.getItalic());
        // newFont.setStrikeout(font.getStrikeout());
        // newFont.setTypeOffset(font.getTypeOffset());
        // newFont.setUnderline(font.getUnderline());

        return newFont;
    }
 
开发者ID:roundrop,项目名称:ermasterr,代码行数:18,代码来源:POIUtils.java

示例8: getHeadCellStyle

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
/**
 * 
 * @Title: getCellStyle
 * @Description: TODO(设置表头样式)
 * @param wb
 * @return
 */
private CellStyle getHeadCellStyle(Workbook wb) {
	CellStyle style = wb.createCellStyle();
	Font font = wb.createFont();
	font.setFontName("宋体");
	font.setFontHeightInPoints((short) 12);// 设置字体大小
	font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
	style.setFillForegroundColor(HSSFColor.LIME.index);// 设置背景色
	style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
	style.setAlignment(HSSFCellStyle.SOLID_FOREGROUND);// 让单元格居中
	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	style.setBorderTop(CellStyle.BORDER_THIN);
	style.setBorderLeft(CellStyle.BORDER_THIN);
	style.setBorderRight(CellStyle.BORDER_THIN);
	style.setBorderBottom(CellStyle.BORDER_THIN);
	// style.setWrapText(true);//设置自动换行
	style.setFont(font);
	return style;
}
 
开发者ID:ls960972314,项目名称:report,代码行数:26,代码来源:ReportServiceImpl.java

示例9: getFontMetrics

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
private FontMetrics getFontMetrics(HSSFFont hf){
    FontMetrics fm;
    Short pFont = new Short(hf.getIndex());

    fm = (FontMetrics) fontMetrics.get(pFont);
    if (fm == null) {
        int style;
        if((hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) || hf.getItalic()) { style = 0; if(hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) style ^= Font.BOLD; if(hf.getItalic()) style ^= Font.ITALIC; } else { style = Font.PLAIN; }
        Font f = new java.awt.Font(hf.getFontName(), style, hf.getFontHeightInPoints());

        if (graphics == null) {
            BufferedImage i = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY); graphics = i.createGraphics(); }

        fm = graphics.getFontMetrics(f);
        fontMetrics.put(pFont, fm);
    }

    return fm;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:ExcelAutoColumnSizer.java

示例10: notifyCellValue

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
public void notifyCellValue(String val, HSSFFont font) {
    if (val == null || val.length() == 0) return;
    if (font == null) throw new IllegalArgumentException("font is null");

    short width;
    {
        FontMetrics fm = getFontMetrics(font);
        int w = fm.stringWidth(val);
        width = (w > Short.MAX_VALUE) ? Short.MAX_VALUE : (short) w;
        // TODO - this gives an underestimate with large font-sizes.
        // TODO - What we *should* be considering is the 'display width'.
        // This means we'd have to take into account cell type & format.
    }

    if (width > currentWidth) {
        currentWidth = width;
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:ExcelAutoColumnSizer.java

示例11: createCellStyleForColumnHeading

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
public static HSSFCellStyle createCellStyleForColumnHeading(HSSFWorkbook workBook) {
	HSSFCellStyle cellStyle = workBook.createCellStyle();
	HSSFFont fontObj = workBook.createFont();
	cellStyle.setBorderBottom(BorderStyle.THIN);
	cellStyle.setBorderTop(BorderStyle.THIN);
	cellStyle.setBorderLeft(BorderStyle.THIN);
	cellStyle.setBorderRight(BorderStyle.THIN);
	cellStyle.setWrapText(true);
	cellStyle.setAlignment(HorizontalAlignment.CENTER);
	cellStyle.setFillBackgroundColor(Short.valueOf("22").shortValue());
	cellStyle.setFillPattern(FillPatternType.BIG_SPOTS);
	cellStyle.setFillForegroundColor(Short.valueOf("22").shortValue());
	cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	fontObj.setFontName("Calibri");
	fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue());
	fontObj.setBold(true);
	fontObj.setColor(Short.valueOf("8").shortValue());
	cellStyle.setFont(fontObj);
	return cellStyle;
}
 
开发者ID:siteadmin,项目名称:CCDA-Score-CARD,代码行数:21,代码来源:ScorecardExcelGenerator.java

示例12: copyFont

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
public static HSSFFont copyFont(HSSFWorkbook workbook, HSSFFont font) {

		HSSFFont newFont = workbook.createFont();

		// newFont.setBoldweight(font.getBoldweight());
		// newFont.setCharSet(font.getCharSet());
		// newFont.setColor(font.getColor());
		// newFont.setFontHeight(font.getFontHeight());
		// newFont.setFontHeightInPoints(font.getFontHeightInPoints());
		// newFont.setFontName(font.getFontName());
		// newFont.setItalic(font.getItalic());
		// newFont.setStrikeout(font.getStrikeout());
		// newFont.setTypeOffset(font.getTypeOffset());
		// newFont.setUnderline(font.getUnderline());

		return newFont;
	}
 
开发者ID:kozake,项目名称:ermaster-k,代码行数:18,代码来源:POIUtils.java

示例13: createPoiFont

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的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

示例14: getHeaderStyle

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
private HSSFCellStyle getHeaderStyle(final int col)
{
	String key = "header-" + col;
	HSSFCellStyle cs_header = m_styles.get(key);
	if (cs_header == null)
	{
		HSSFFont font_header = getFont(true);
		cs_header = m_workbook.createCellStyle();
		cs_header.setFont(font_header);
		cs_header.setBorderLeft((short)2);
		cs_header.setBorderTop((short)2);
		cs_header.setBorderRight((short)2);
		cs_header.setBorderBottom((short)2);
		cs_header.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
		cs_header.setWrapText(true);
		m_styles.put(key, cs_header);
	}
	return cs_header;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:20,代码来源:AbstractExcelExporter.java

示例15: createSecondTitleStyle

import org.apache.poi.hssf.usermodel.HSSFFont; //导入依赖的package包/类
private HSSFCellStyle createSecondTitleStyle(HSSFWorkbook wb){
	HSSFCellStyle style = wb.createCellStyle();
	style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
	style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
	style.setBorderBottom(HSSFCellStyle.BORDER_NONE);
    style.setBorderLeft(HSSFCellStyle.BORDER_NONE);
    style.setBorderRight(HSSFCellStyle.BORDER_NONE);
    style.setBorderTop(HSSFCellStyle.BORDER_NONE);
	style.setWrapText(true);
	
	HSSFFont font = wb.createFont();
	//font.setFontHeightInPoints((short)20);
	font.setFontName("����");
	style.setFont(font);
	return style;
}
 
开发者ID:wallellen,项目名称:wl,代码行数:17,代码来源:ExcelExcuter.java


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