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


Java SXSSFWorkbook.createFont方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.streaming.SXSSFWorkbook.createFont方法的典型用法代码示例。如果您正苦于以下问题:Java SXSSFWorkbook.createFont方法的具体用法?Java SXSSFWorkbook.createFont怎么用?Java SXSSFWorkbook.createFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.streaming.SXSSFWorkbook的用法示例。


在下文中一共展示了SXSSFWorkbook.createFont方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createXSSFCellStyle

import org.apache.poi.xssf.streaming.SXSSFWorkbook; //导入方法依赖的package包/类
private XSSFCellStyle createXSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
	SXSSFWorkbook workbook = (SXSSFWorkbook) wb;
	XSSFFont titleFont = (XSSFFont) workbook.createFont();
	titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
	titleFont.setFontName("宋体");

	XSSFColor color9 = new XSSFColor(new java.awt.Color(fontColor[0], fontColor[1], fontColor[2]));
	XSSFColor color10 = new XSSFColor(new java.awt.Color(bgColor[0], bgColor[1], bgColor[2]));
	
	if (!(fontColor[0] == 0 && fontColor[1] == 0 && fontColor[2] == 0)) {
		titleFont.setColor(color9);
	}
	titleFont.setBold(true);
	titleFont.setFontHeightInPoints((short) fontSize);

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

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

示例2: createXSSFCellStyles

import org.apache.poi.xssf.streaming.SXSSFWorkbook; //导入方法依赖的package包/类
private Map<String, CellStyle> createXSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor,
		int[] headerFontColor, int headerFontSize, int headerAlign) {
	Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

	SXSSFWorkbook workbook = (SXSSFWorkbook) wb;
	XSSFColor xssfContextBgColor = new XSSFColor(new java.awt.Color(contextBgColor[0], contextBgColor[1], contextBgColor[2]));
	XSSFColor xssfContextFontColor = new XSSFColor(new java.awt.Color(contextFontColor[0], contextFontColor[1], contextFontColor[2]));
	XSSFColor xssfHeaderBgColor = new XSSFColor(new java.awt.Color(headerBgColor[0], headerBgColor[1], headerBgColor[2]));
	XSSFColor xssfHeaderFontColor = new XSSFColor(new java.awt.Color(headerFontColor[0], headerFontColor[1], headerFontColor[2]));

	XSSFFont headerFont = (XSSFFont) workbook.createFont();
	headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
	headerFont.setFontName("宋体");
	if (!(headerFontColor[0] == 0 && headerFontColor[1] == 0 && headerFontColor[2] == 0)) {
		headerFont.setColor(xssfHeaderFontColor);
	}
	headerFont.setBold(true);
	headerFont.setFontHeightInPoints((short) headerFontSize);
	XSSFCellStyle headerStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true);
	headerStyle.setFont(headerFont);
	headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	headerStyle.setFillForegroundColor(xssfHeaderBgColor);
	this.setCellStyleAligment(headerStyle, headerAlign);
	headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	styles.put(GridStyleType.headerStyle.name(), headerStyle);

	XSSFFont dataFont = (XSSFFont) workbook.createFont();
	if (!(contextFontColor[0] == 0 && contextFontColor[1] == 0 && contextFontColor[2] == 0)) {
		dataFont.setColor(xssfContextFontColor);
	}
	dataFont.setFontHeightInPoints((short) contextFontSize);
	dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
	dataFont.setFontName("宋体");

	XSSFCellStyle dataAlignLeftStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true);
	dataAlignLeftStyle.setFont(dataFont);
	dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dataAlignLeftStyle.setFillForegroundColor(xssfContextBgColor);
	dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	dataAlignLeftStyle.setWrapText(true);
	dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT);
	styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle);

	XSSFCellStyle dataAlignCenterStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true);
	dataAlignCenterStyle.setFont(dataFont);
	dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dataAlignCenterStyle.setFillForegroundColor(xssfContextBgColor);
	dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	dataAlignCenterStyle.setWrapText(true);
	dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER);
	styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle);

	XSSFCellStyle dataAlignRightStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true);
	dataAlignRightStyle.setFont(dataFont);
	dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dataAlignRightStyle.setFillForegroundColor(xssfContextBgColor);
	dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	dataAlignRightStyle.setWrapText(true);
	dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT);
	styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle);

	XSSFCellStyle dateStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true);
	CreationHelper helper = workbook.getCreationHelper();
	dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm"));
	dateStyle.setFont(dataFont);
	dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dateStyle.setFillForegroundColor(xssfContextBgColor);
	dateStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	this.setCellStyleAligment(dateStyle, contextFontAlign);
	styles.put(GridStyleType.dateStyle.name(), dateStyle);

	return styles;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:74,代码来源:GridStyleBuilder.java

示例3: testWriteExcelFileAttribute

import org.apache.poi.xssf.streaming.SXSSFWorkbook; //导入方法依赖的package包/类
/**
 * [Flow #-3] 엑셀 파일 속성 수정 : 엑셀 파일의 속성(셀의 크기, Border의 속성, 셀의 색상, 정렬 등)을 수정함
 */
@Test
public void testWriteExcelFileAttribute() throws Exception {
    
    try {
    	log.debug("testWriteExcelFileAttribute start....");

    	short rowheight = 40;
    	int columnwidth = 30;
    	
    	StringBuffer sb = new StringBuffer();
    	sb.append(fileLocation).append("/").append("testWriteExcelFileAttribute.xlsx");        	

    	// delete file
    	if (EgovFileUtil.isExistsFile(sb.toString())) {
    		EgovFileUtil.delete(new File(sb.toString()));
    	
    		log.debug("Delete file...." + sb.toString());
    	}
    	
    	SXSSFWorkbook wb = new SXSSFWorkbook();
    	
    	Sheet sheet1 = wb.createSheet("new sheet");
        wb.createSheet("second sheet");
        
        // 셀의 크기
    	sheet1.setDefaultRowHeight(rowheight);
    	sheet1.setDefaultColumnWidth(columnwidth);
    	
    	Font f2 = wb.createFont();
    	CellStyle cs = wb.createCellStyle();
    	cs = wb.createCellStyle();

        cs.setFont( f2 );
        cs.setWrapText( true );
     
        // 정렬
        cs.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

        cs.setFillPattern(HSSFCellStyle.DIAMONDS); // 무늬 스타일
        
        // 셀의 색상
        cs.setFillForegroundColor(new HSSFColor.BLUE().getIndex()); // 무늬 색
        cs.setFillBackgroundColor(new HSSFColor.RED().getIndex());  // 배경색
        
    	sheet1.setDefaultColumnStyle((short) 0, cs);
    	
        Workbook tmp = excelService.createSXSSFWorkbook(wb, sb.toString());

        Sheet sheetTmp1 = tmp.getSheetAt(0);

        assertEquals(rowheight, sheetTmp1.getDefaultRowHeight());
        assertEquals(columnwidth, sheetTmp1.getDefaultColumnWidth());
        
        CellStyle cs1 = tmp.getCellStyleAt((short)(tmp.getNumCellStyles() - 1));

        log.debug("getAlignment : " + cs1.getAlignment());
    	assertEquals(HSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment());
    	
    	log.debug("getFillPattern : " + cs1.getFillPattern());
    	assertEquals(HSSFCellStyle.DIAMONDS, cs1.getFillPattern());
    	
    	log.debug("getFillForegroundColor : " + cs1.getFillForegroundColor());
    	log.debug("getFillBackgroundColor : " + cs1.getFillBackgroundColor());
    	assertEquals(new HSSFColor.BLUE().getIndex(), cs1.getFillForegroundColor());
    	assertEquals(new HSSFColor.RED().getIndex(), cs1.getFillBackgroundColor());        	


    } catch (Exception e) {
    	log.error(e.toString());
    	throw new Exception(e);
    } finally {
    	log.debug("testWriteExcelFileAttribute end....");
    }
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:78,代码来源:EgovExcelSXSSFServiceTest.java


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