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


Java CellStyle.cloneStyleFrom方法代碼示例

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


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

示例1: createStyles

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

示例2: createStyles

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

示例3: copyCellStyle

import org.apache.poi.ss.usermodel.CellStyle; //導入方法依賴的package包/類
/**
 * 複製單元格樣式
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-18
 * @version     v1.0
 *
 * @param i_FromCellStyle  源單元格樣式
 * @param i_ToCellStyle    目標單元格樣式
 */
public final static void copyCellStyle(CellStyle i_FromCellStyle ,CellStyle i_ToCellStyle)
{
    if ( i_FromCellStyle instanceof HSSFCellStyle )
    {
        i_ToCellStyle.cloneStyleFrom(i_FromCellStyle);
        /*
        i_ToCellStyle.setAlignment(          i_FromCellStyle.getAlignmentEnum());
        i_ToCellStyle.setDataFormat(         i_FromCellStyle.getDataFormat());
        
        // 邊框和邊框顏色
        i_ToCellStyle.setBorderBottom(       i_FromCellStyle.getBorderBottomEnum());
        i_ToCellStyle.setBorderLeft(         i_FromCellStyle.getBorderLeftEnum());
        i_ToCellStyle.setBorderRight(        i_FromCellStyle.getBorderRightEnum());
        i_ToCellStyle.setBorderTop(          i_FromCellStyle.getBorderTopEnum());
        i_ToCellStyle.setLeftBorderColor(    i_FromCellStyle.getLeftBorderColor());
        i_ToCellStyle.setRightBorderColor(   i_FromCellStyle.getRightBorderColor());
        i_ToCellStyle.setTopBorderColor(     i_FromCellStyle.getTopBorderColor());
        i_ToCellStyle.setBottomBorderColor(  i_FromCellStyle.getBottomBorderColor());
        
        // 背景和前景
        i_ToCellStyle.setFillBackgroundColor(i_FromCellStyle.getFillBackgroundColor());
        i_ToCellStyle.setFillForegroundColor(i_FromCellStyle.getFillForegroundColor());
        i_ToCellStyle.setFillPattern(        i_FromCellStyle.getFillPatternEnum());
        i_ToCellStyle.setHidden(             i_FromCellStyle.getHidden());
        
        // 首行縮進
        i_ToCellStyle.setIndention(          i_FromCellStyle.getIndention());
        i_ToCellStyle.setLocked(             i_FromCellStyle.getLocked());
  
        // 旋轉
        i_ToCellStyle.setShrinkToFit(        i_FromCellStyle.getShrinkToFit());
        i_ToCellStyle.setRotation(           i_FromCellStyle.getRotation());
        i_ToCellStyle.setVerticalAlignment(  i_FromCellStyle.getVerticalAlignmentEnum());
        i_ToCellStyle.setWrapText(           i_FromCellStyle.getWrapText());
        */
    }
    else if ( i_FromCellStyle instanceof XSSFCellStyle )
    {
        i_ToCellStyle.cloneStyleFrom(i_FromCellStyle);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:52,代碼來源:ExcelHelp.java


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