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


Java SXSSFWorkbook.createCellStyle方法代码示例

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


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

示例1: exportExcelTemplate

import org.apache.poi.xssf.streaming.SXSSFWorkbook; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void exportExcelTemplate(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	List<VariableCategory> variableCategories=(List<VariableCategory>)httpSessionKnowledgeCache.get(req, VCS_KEY);
	if(variableCategories==null){
		KnowledgeBase knowledgeBase=buildKnowledgeBase(req);
		variableCategories=knowledgeBase.getResourceLibrary().getVariableCategories();
	}
	SXSSFWorkbook wb = new SXSSFWorkbook();
	XSSFCellStyle style=(XSSFCellStyle)wb.createCellStyle();
	Color c=new Color(147,208,15);
	XSSFColor xssfColor=new XSSFColor(c);
	style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	style.setFillForegroundColor(xssfColor);
	for(VariableCategory vc:variableCategories){
		buildSheet(wb, vc,style);
	}
	resp.setContentType("application/x-xls");
	resp.setHeader("Content-Disposition","attachment; filename=urule-batch-test-template.xlsx");
	OutputStream outputStream=resp.getOutputStream();
	wb.write(outputStream);;
	outputStream.flush();
	outputStream.close();
}
 
开发者ID:youseries,项目名称:urule,代码行数:24,代码来源:PackageServletHandler.java

示例2: createDateCellStyle

import org.apache.poi.xssf.streaming.SXSSFWorkbook; //导入方法依赖的package包/类
private CellStyle createDateCellStyle(SXSSFWorkbook workbook) {
	CreationHelper createHelper = workbook.getCreationHelper();
	CellStyle cellStyle = workbook.createCellStyle();
	cellStyle
			.setDataFormat(createHelper.createDataFormat().getFormat(Messages.getString("Format.Export.DateTime")));
	return cellStyle;
}
 
开发者ID:tilioteo,项目名称:hypothesis,代码行数:8,代码来源:ExportThreadedServiceImpl.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.createCellStyle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。