當前位置: 首頁>>代碼示例>>Java>>正文


Java Font.setFontName方法代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.Font.setFontName方法的典型用法代碼示例。如果您正苦於以下問題:Java Font.setFontName方法的具體用法?Java Font.setFontName怎麽用?Java Font.setFontName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.ss.usermodel.Font的用法示例。


在下文中一共展示了Font.setFontName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeHeader

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
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 );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:24,代碼來源:ExportEventsImpl.java

示例2: createStyles

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
     * 創建表格樣式
     * @param wb 工作薄對象
     * @return 樣式列表
     */
    private Map<String, CellStyle> createStyles(Workbook wb) {
        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

        CellStyle style = wb.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        Font titleFont = wb.createFont();
        titleFont.setFontName("Arial");
        titleFont.setFontHeightInPoints((short) 16);
        titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        style.setFont(titleFont);
        styles.put("title", style);

        style = wb.createCellStyle();
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        style.setBorderRight(CellStyle.BORDER_THIN);
        style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderLeft(CellStyle.BORDER_THIN);
        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderTop(CellStyle.BORDER_THIN);
        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderBottom(CellStyle.BORDER_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(CellStyle.ALIGN_LEFT);
        styles.put("data1", style);

        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get("data"));
        style.setAlignment(CellStyle.ALIGN_CENTER);
        styles.put("data2", style);

        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get("data"));
        style.setAlignment(CellStyle.ALIGN_RIGHT);
        styles.put("data3", style);

        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get("data"));
//		style.setWrapText(true);
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        Font headerFont = wb.createFont();
        headerFont.setFontName("Arial");
        headerFont.setFontHeightInPoints((short) 10);
        headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        headerFont.setColor(IndexedColors.WHITE.getIndex());
        style.setFont(headerFont);
        styles.put("header", style);

        return styles;
    }
 
開發者ID:sombie007,項目名稱:ExcelHandle,代碼行數:66,代碼來源:ExportExcel.java

示例3: initFonts

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * Initialisation des polices
 */
protected void initFonts() {
	Font fontHeader = workbook.createFont();
	fontHeader.setFontHeightInPoints(getHeaderFontHeight());
	fontHeader.setFontName(getFontName());
	fontHeader.setBoldweight(Font.BOLDWEIGHT_BOLD);
	setFontColor(fontHeader, colorRegistry, HEADER_FONT_COLOR_INDEX);
	registerFont(FONT_HEADER_NAME, fontHeader);

	Font fontNormal = workbook.createFont();
	fontNormal.setFontHeightInPoints(getNormalFontHeight());
	fontNormal.setFontName(getFontName());
	registerFont(FONT_NORMAL_NAME, fontNormal);
	
	Font fontLink = workbook.createFont();
	fontLink.setFontHeightInPoints(getNormalFontHeight());
	fontLink.setFontName(getFontName());
	fontLink.setUnderline(Font.U_SINGLE);
	setFontColor(fontLink, colorRegistry, LINK_FONT_COLOR_INDEX);
	registerFont(FONT_LINK_NAME, fontLink);
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:24,代碼來源:AbstractExcelTableExport.java

示例4: initFont

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * 初始化字體樣式
 *
 * @param font
 * @param fontBean
 */
private void initFont(Font font, FontStyleBean fontBean) {
    font.setFontName(fontBean.getName());
    font.setFontHeightInPoints(fontBean.getSize());

    if (fontBean.getBoldWeight() != null) {
        font.setBoldweight(fontBean.getBoldWeight());
    }

    if (fontBean.getItalic() != null) {
        font.setItalic(fontBean.getItalic());
    }

    if (fontBean.getUnderLine() != null) {
        font.setUnderline(fontBean.getUnderLine());
    }

    if (fontBean.getColor() != null) {
        ColorBean cbean = fontBean.getColor();

        ((XSSFFont) font).setColor(new XSSFColor(new Color(cbean.getR(), cbean.getG(), cbean.getB())));
    }

}
 
開發者ID:cgfalcon,項目名稱:fluentexcel,代碼行數:30,代碼來源:XlsxRender.java

示例5: createStyles

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * excel 樣式
 *
 * @return
 */
public Map<String, CellStyle> createStyles(Workbook workbook) {
    Map<String, CellStyle> styles = new HashMap();
    CellStyle style = workbook.createCellStyle();
    style.setAlignment((short) 2);
    style.setVerticalAlignment((short) 1);
    Font titleFont = workbook.createFont();
    titleFont.setFontName("Arial");
    titleFont.setFontHeightInPoints((short) 16);
    titleFont.setBoldweight((short) 700);
    style.setFont(titleFont);
    styles.put("title", style);
    style = workbook.createCellStyle();
    style.setVerticalAlignment((short) 1);
    style.setBorderRight((short) 1);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft((short) 1);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop((short) 1);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom((short) 1);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    Font dataFont = workbook.createFont();
    dataFont.setFontName("Arial");
    dataFont.setFontHeightInPoints((short) 10);
    style.setFont(dataFont);
    styles.put("data", style);
    style = workbook.createCellStyle();
    style.cloneStyleFrom((CellStyle) styles.get("data"));
    style.setAlignment((short) 1);
    styles.put("data1", style);
    style = workbook.createCellStyle();
    style.cloneStyleFrom((CellStyle) styles.get("data"));
    style.setAlignment((short) 2);
    styles.put("data2", style);
    style = workbook.createCellStyle();
    style.cloneStyleFrom((CellStyle) styles.get("data"));
    style.setAlignment((short) 3);
    styles.put("data3", style);
    style = workbook.createCellStyle();
    style.cloneStyleFrom((CellStyle) styles.get("data"));
    style.setAlignment((short) 2);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern((short) 1);
    Font headerFont = workbook.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setBoldweight((short) 700);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(headerFont);
    styles.put("header", style);
    return styles;
}
 
開發者ID:zhangbiy,項目名稱:exportExcel,代碼行數:58,代碼來源:ExcelTest.java

示例6: copyFont

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * 複製字體
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-18
 * @version     v1.0
 *
 * @param i_FromFont  源字體
 * @param i_ToFont    目標字體
 */
public final static void copyFont(Font i_FromFont ,Font i_ToFont)
{
    i_ToFont.setBold(              i_FromFont.getBold());
    i_ToFont.setCharSet(           i_FromFont.getCharSet());
    i_ToFont.setColor(             i_FromFont.getColor());
    i_ToFont.setFontHeight(        i_FromFont.getFontHeight());
    i_ToFont.setFontHeightInPoints(i_FromFont.getFontHeightInPoints());
    i_ToFont.setFontName(          i_FromFont.getFontName());
    i_ToFont.setItalic(            i_FromFont.getItalic());
    i_ToFont.setStrikeout(         i_FromFont.getStrikeout());
    i_ToFont.setTypeOffset(        i_FromFont.getTypeOffset());
    i_ToFont.setUnderline(         i_FromFont.getUnderline());
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:24,代碼來源:ExcelHelp.java

示例7: setCommonStyle

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * 設置通用的對齊居中、邊框等
 *
 * @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);
}
 
開發者ID:goribun,項目名稱:excel-rw-annotation,代碼行數:29,代碼來源:StyleConfiguration.java

示例8: startExport

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
@Override public void startExport(List<? extends IExportColumn<?>> columnList) throws Exception {
	if(m_started)
		throw new IllegalArgumentException("The writer was already started");
	m_started = true;
	m_columnList = columnList;
	Workbook wb = m_workbook = createWorkbook();
	Font defaultFont = wb.createFont();
	defaultFont.setFontHeightInPoints((short) 10);
	defaultFont.setFontName("Arial");

	CellStyle dcs = m_defaultCellStyle = wb.createCellStyle();
	dcs.setFont(defaultFont);

	// FIXME Date format must be locale dependent?
	CellStyle dates = m_dateStyle = wb.createCellStyle();
	dates.setDataFormat(wb.createDataFormat().getFormat("d-m-yyyy"));
	dates.setFont(defaultFont);

	CellStyle curs = m_currencyStyle = wb.createCellStyle();
	curs.setDataFormat(wb.createDataFormat().getFormat("#,##0.00"));
	curs.setFont(defaultFont);

	CellStyle nums = m_numberStyle = wb.createCellStyle();
	nums.setDataFormat(wb.createDataFormat().getFormat("#0"));
	nums.setFont(defaultFont);

	Font headerFont = wb.createFont();
	headerFont.setFontHeightInPoints((short) 10);
	headerFont.setColor((short) 0xc);
	headerFont.setBold(true);
	headerFont.setFontName("Arial");

	CellStyle hds = m_headerStyle = wb.createCellStyle();
	hds.setBorderBottom(BorderStyle.THIN);
	hds.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
	hds.setFont(headerFont);

	createNewSheet(columnList);
}
 
開發者ID:fjalvingh,項目名稱:domui,代碼行數:40,代碼來源:ExcelExportWriter.java

示例9: getHeadCellStyle

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的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

示例10: setBold

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * Set a bold font for the given cell with a given font size (in pt).
 * 
 * @param wb
 *            the workbook that contains the cell
 * @param cell
 *            the cell where the text is contained
 * @param size
 *            the size in pt of the text
 */
public static void setBold(Workbook wb, HSSFCell cell, short size) {
	Font font = wb.createFont();
	font.setFontHeightInPoints((short) size);
	font.setFontName("Arial");
	font.setColor(IndexedColors.BLACK.getIndex());
	font.setBold(true);
	font.setItalic(false);

	CellStyle style = wb.createCellStyle();
	style.setFont(font);
	cell.setCellStyle(style);
}
 
開發者ID:turnus,項目名稱:turnus,代碼行數:23,代碼來源:PoiUtils.java

示例11: getHeaderStyle

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * header樣式
 *
 * @return
 */
public CellStyle getHeaderStyle() {
    CellStyle headerStyle = workbook.createCellStyle();

    // 設置單元格的背景顏色為淡藍色
    headerStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    // 設置單元格居中對齊
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    // 設置單元格垂直居中對齊
    headerStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    // 創建單元格內容顯示不下時自動換行
    headerStyle.setWrapText(true);
    // 設置單元格字體樣式
    Font font = workbook.createFont();
    // 設置字體加粗
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontName("宋體");
    font.setFontHeight((short) 200);
    headerStyle.setFont(font);
    // 設置單元格邊框為細線條
    setBorder(headerStyle);

    return headerStyle;
}
 
開發者ID:goribun,項目名稱:common-utils,代碼行數:30,代碼來源:StyleConfiguration.java

示例12: getTextStyle

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
/**
 * 文本樣式
 *
 * @return
 */
public CellStyle getTextStyle() {
    CellStyle textStyle = workbook.createCellStyle();

    // 設置單元格居中對齊
    textStyle.setAlignment(CellStyle.ALIGN_CENTER);
    // 設置單元格垂直居中對齊
    textStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    // 創建單元格內容顯示不下時自動換行
    textStyle.setWrapText(true);
    // 設置單元格字體樣式
    Font font = workbook.createFont();
    // 設置字體加粗
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontName("宋體");
    font.setFontHeight((short) 200);
    textStyle.setFont(font);
    // 設置單元格邊框為細線條
    setBorder(textStyle);

    return textStyle;
}
 
開發者ID:goribun,項目名稱:common-utils,代碼行數:27,代碼來源:StyleConfiguration.java

示例13: getNumberStyle

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
public CellStyle getNumberStyle() {
    CellStyle numberStyle = workbook.createCellStyle();
    // 設置單元格居中對齊
    numberStyle.setAlignment(CellStyle.ALIGN_CENTER);
    // 設置單元格垂直居中對齊
    numberStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    // 創建單元格內容顯示不下時自動換行
    numberStyle.setWrapText(true);
    // 設置單元格字體樣式
    Font font = workbook.createFont();
    // 設置字體加粗
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontName("宋體");
    font.setFontHeight((short) 200);
    numberStyle.setFont(font);
    // 設置單元格邊框為細線條
    setBorder(numberStyle);

    return numberStyle;
}
 
開發者ID:goribun,項目名稱:common-utils,代碼行數:21,代碼來源:StyleConfiguration.java

示例14: getDateStyle

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
public CellStyle getDateStyle() {
    CellStyle dateStyle = workbook.createCellStyle();
    // 設置單元格居中對齊
    dateStyle.setAlignment(CellStyle.ALIGN_CENTER);
    // 設置單元格垂直居中對齊
    dateStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    DataFormat format = workbook.createDataFormat();
    dateStyle.setDataFormat(format.getFormat("yyyy-MM-dd HH:mm"));
    // 創建單元格內容顯示不下時自動換行
    dateStyle.setWrapText(true);
    // 設置單元格字體樣式
    Font font = workbook.createFont();
    // 設置字體加粗
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontName("宋體");
    font.setFontHeight((short) 200);
    dateStyle.setFont(font);
    setBorder(dateStyle);
    return dateStyle;
}
 
開發者ID:goribun,項目名稱:common-utils,代碼行數:21,代碼來源:StyleConfiguration.java

示例15: createFont

import org.apache.poi.ss.usermodel.Font; //導入方法依賴的package包/類
@Override
public PoiFont createFont(com.dua3.utility.text.Font font) {
    Font poiFont = poiWorkbook.createFont();
    poiFont.setFontName(font.getFamily());
    poiFont.setFontHeight(((short) Math.round(20*font.getSizeInPoints())));
    poiFont.setColor(getPoiColor(font.getColor()).getIndex());
    poiFont.setBold(font.isBold());
    poiFont.setItalic(font.isItalic());
    poiFont.setUnderline(font.isUnderlined() ? org.apache.poi.ss.usermodel.Font.U_SINGLE
            : org.apache.poi.ss.usermodel.Font.U_NONE);
    poiFont.setStrikeout(font.isStrikeThrough());
    return new PoiFont(this, poiFont);
}
 
開發者ID:xzel23,項目名稱:meja,代碼行數:14,代碼來源:PoiWorkbook.java


注:本文中的org.apache.poi.ss.usermodel.Font.setFontName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。