當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。