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


Java XSSFCellStyle类代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCellStyle的典型用法代码示例。如果您正苦于以下问题:Java XSSFCellStyle类的具体用法?Java XSSFCellStyle怎么用?Java XSSFCellStyle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XSSFCellStyle类属于org.apache.poi.xssf.usermodel包,在下文中一共展示了XSSFCellStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSheet

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
private void buildSheet(SXSSFWorkbook wb,VariableCategory vc,XSSFCellStyle style){
	String name=vc.getName();
	Sheet sheet=wb.createSheet(name);
	Row row=sheet.createRow(0);
	List<Variable> variables=vc.getVariables();
	for(int i=0;i<variables.size();i++){
		sheet.setColumnWidth(i,4000);
		Cell cell=row.createCell(i);
		Variable var=variables.get(i);
		cell.setCellValue(var.getLabel());
		cell.setCellStyle(style);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:14,代码来源:PackageServletHandler.java

示例2: createBackgroundColorXSSFCellStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * @param wb
 * @param color
 * @param foreGround
 * @return
 */
public static XSSFCellStyle createBackgroundColorXSSFCellStyle(XSSFWorkbook wb,XSSFColor color,short foreGround){
	String message="XSSFWorkbook must not be null!";
	Objects.requireNonNull(wb, () -> message);
	XSSFCellStyle cellStyle=wb.createCellStyle();
	cellStyle.setWrapText(true);
	cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
	cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
	cellStyle.setBorderBottom(BorderStyle.THIN);
	cellStyle.setBorderLeft(BorderStyle.THIN);
	cellStyle.setBorderTop(BorderStyle.THIN);
	cellStyle.setBorderRight(BorderStyle.THIN);
	cellStyle.setFillForegroundColor(color);
	cellStyle.setFillPattern(foreGround);
	return cellStyle;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:22,代码来源:XSSFCellUtil.java

示例3: getCellStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * Fixed all properties suitable for cell-related style.
 * 
 * @param workbook Excel Workbook
 * @param boardStyle all properties suitable on the style of a cell
 * @param font a font
 * @return the customized style
 */
protected static CellStyle getCellStyle(Workbook workbook, TableStyle boardStyle, Font font) {
  XSSFCellStyle cellStyle = (XSSFCellStyle) workbook.createCellStyle();
  if (boardStyle.getFillColor() != null) {
    cellStyle.setFillForegroundColor(boardStyle.getFillColor());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
  }
  cellStyle.setBorderLeft(boardStyle.getCellBorderLeft());
  cellStyle.setBorderRight(boardStyle.getCellBorderRight());
  cellStyle.setBorderTop(boardStyle.getCellBorderTop());
  cellStyle.setBorderBottom(boardStyle.getCellBorderBottom());
  cellStyle.setAlignment(boardStyle.getAlignment());

  cellStyle.setBorderColor(BorderSide.LEFT, boardStyle.getBorderColor());
  cellStyle.setBorderColor(BorderSide.RIGHT, boardStyle.getBorderColor());
  cellStyle.setBorderColor(BorderSide.TOP, boardStyle.getBorderColor());
  cellStyle.setBorderColor(BorderSide.BOTTOM, boardStyle.getBorderColor());

  if (font != null) {
    cellStyle.setFont(font);
  }
  return cellStyle;
}
 
开发者ID:lynchmaniac,项目名称:poilight,代码行数:31,代码来源:PoiLightStyle.java

示例4: insertDedicatedStyleCell

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
public static void insertDedicatedStyleCell(XSSFRow row,int col,XSSFCellStyle style,String value){
	String message="XSSFRow or XSSFCellStyle must not be null!";
	Objects.requireNonNull(row, () -> message);
	Objects.requireNonNull(style, () -> message);
	XSSFCell cell=createCellIfNotPresent(row,col);
	setCellProperties(createCellIfNotPresent(row, col), value, style);
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:8,代码来源:XSSFCellUtil.java

示例5: copySheets

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * @param newSheet the sheet to create from the copy.
 * @param sheet the sheet to copy.
 * @param copyStyle true copy the style.
 */
public static void copySheets(XSSFSheet newSheet, XSSFSheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, XSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, XSSFCellStyle>() : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
        XSSFRow srcRow = sheet.getRow(i);
        XSSFRow destRow = newSheet.createRow(i);
        if (srcRow != null) {
            Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
            if (srcRow.getLastCellNum() > maxColumnNum) {
                maxColumnNum = srcRow.getLastCellNum();
            }
        }
    }
    for (int i = 0; i <= maxColumnNum; i++) {
        newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
    }
   //Util.copyPictures(newSheet,sheet) ;
}
 
开发者ID:likelet,项目名称:DAtools,代码行数:24,代码来源:Util.java

示例6: copyRow

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * @param srcSheet the sheet to copy.
 * @param destSheet the sheet to create.
 * @param srcRow the row to copy.
 * @param destRow the row to create.
 * @param styleMap -
 */
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, XSSFRow srcRow, XSSFRow destRow, Map<Integer, XSSFCellStyle> styleMap) {
    // manage a list of merged zone in order to not insert two times a merged zone  
    Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
    destRow.setHeight(srcRow.getHeight());
    // pour chaque row  
    for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
        if(j<0){
        }else{
            XSSFCell oldCell = srcRow.getCell(j);   // ancienne cell  
        XSSFCell newCell = destRow.getCell(j);  // new cell   
        if (oldCell != null) {
            if (newCell == null) {
                newCell = destRow.createCell(j);
            }
            // copy chaque cell  
            copyCell(oldCell, newCell, styleMap);
                  // copy les informations de fusion entre les cellules  
            //System.out.println("row num: " + srcRow.getRowNum() + " , col: " + (short)oldCell.getColumnIndex());  
            CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());

            if (mergedRegion != null) {
                //System.out.println("Selected merged region: " + mergedRegion.toString());  
                CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
                //System.out.println("New merged region: " + newMergedRegion.toString());  
                CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
                if (isNewMergedRegion(wrapper, mergedRegions)) {
                    mergedRegions.add(wrapper);
                    destSheet.addMergedRegion(wrapper.range);
                }
            }
        }
        }
        
    }

}
 
开发者ID:likelet,项目名称:DAtools,代码行数:44,代码来源:Util.java

示例7: setBorderStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
@Override
public void setBorderStyle(Direction d, BorderStyle borderStyle) {
    org.apache.poi.ss.usermodel.BorderStyle poiBorder = getPoiBorder(borderStyle);
    final Color color = borderStyle.getColor();
    XSSFColor poiColor = color == null ? null : ((PoiXssfWorkbook) workbook).getPoiColor(color);
    switch (d) {
    case NORTH:
        ((XSSFCellStyle) poiCellStyle).setTopBorderColor(poiColor);
        poiCellStyle.setBorderTop(poiBorder);
        break;
    case EAST:
        ((XSSFCellStyle) poiCellStyle).setRightBorderColor(poiColor);
        poiCellStyle.setBorderRight(poiBorder);
        break;
    case SOUTH:
        ((XSSFCellStyle) poiCellStyle).setBottomBorderColor(poiColor);
        poiCellStyle.setBorderBottom(poiBorder);
        break;
    case WEST:
        ((XSSFCellStyle) poiCellStyle).setLeftBorderColor(poiColor);
        poiCellStyle.setBorderLeft(poiBorder);
        break;
    default:
        throw new IllegalArgumentException();
    }
}
 
开发者ID:xzel23,项目名称:meja,代码行数:27,代码来源:PoiCellStyle.java

示例8: handleNumber

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
@Override
public void handleNumber(XSSFCellStyle style, String number) {
    rawValues.add(number);
    if (style != null) {
        short formatIndex = style.getDataFormat();
        String formatString = style.getDataFormatString();
        if (formatString == null) {
            formatString = BuiltinFormats.getBuiltinFormat(formatIndex);
        }
        if (formatString != null) {
            formattedValues.add(formatter.formatRawCellContents(Double.parseDouble(number), formatIndex, formatString));
            if (formatString.contentEquals("D/M/YYYY")) {
                rawValues.add(formatter.formatRawCellContents(Double.parseDouble(number), formatIndex, formatString));
            }
        }
    }else{
       formattedValues.add(number);
    }
}
 
开发者ID:iMDT,项目名称:xlsx-io,代码行数:20,代码来源:DefaultDataHandlerImpl.java

示例9: createTitle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
protected void createTitle() {
	short lineThickness = (short) (6 * BASE_HEIGHT);
	
	// Top Line
	Row row = sheet.createRow(ROW_4);
	row.setHeight(lineThickness);
	
	XSSFCellStyle style = wb.createCellStyle();
	style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
	setDummyTitleStyle(row,style);
	
	// Title
	row = sheet.createRow(ROW_5);
	row.setHeightInPoints(100);
	sheet.addMergedRegion(CellRangeAddress.valueOf("B5:G5"));
	
	Font font = wb.createFont();
	font.setFontHeightInPoints((short)28);
	font.setFontName("Trebuchet MS");
	font.setBoldweight(Font.BOLDWEIGHT_BOLD);
	style = wb.createCellStyle();
	style.setFont(font);
	style.setAlignment(CellStyle.ALIGN_CENTER);
	style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

	setDummyTitleStyle(row,style);
	row.getCell(COL_B).setCellValue("Open Source License Verification Report");
	
	// Bottom Line
	row = sheet.createRow(ROW_6);
	row.setHeight(lineThickness);
	
	style = wb.createCellStyle();
	style.setFillForegroundColor(DARK_BLUE);
	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
	setDummyTitleStyle(row,style);
}
 
开发者ID:spdx,项目名称:ATTIC-osit,代码行数:39,代码来源:CoverSheetTemplate.java

示例10: getCellStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * @param color
 * @param font
 * @return CellStyle
 */
protected XSSFCellStyle getCellStyle(XSSFColor color, Font font) {
	XSSFCellStyle style = wb.createCellStyle();
	style.setFillForegroundColor(color);
	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
	style.setAlignment(CellStyle.ALIGN_CENTER);
	style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
	style.setWrapText(true);	// new line
	
	style.setBorderBottom(CellStyle.BORDER_THIN);
	style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
	style.setBorderLeft(CellStyle.BORDER_THIN);
	style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
	style.setBorderRight(CellStyle.BORDER_THIN);
	style.setRightBorderColor(IndexedColors.BLACK.getIndex());
	style.setBorderTop(CellStyle.BORDER_THIN);
	style.setTopBorderColor(IndexedColors.BLACK.getIndex());
	
	if(font != null) style.setFont(font);
	
	return style;
}
 
开发者ID:spdx,项目名称:ATTIC-osit,代码行数:27,代码来源:ISheetTemplate.java

示例11: setFormatString

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * Read the numeric format string out of the styles table for this cell. Stores the result in the Cell.
 *
 * @param startElement
 * @param cell
 */
void setFormatString(StartElement startElement, StreamingCell cell) {
    Attribute cellStyle = startElement.getAttributeByName(new QName("s"));
    String cellStyleString = (cellStyle != null) ? cellStyle.getValue() : null;
    XSSFCellStyle style = null;

    if (cellStyleString != null) {
        style = stylesTable.getStyleAt(Integer.parseInt(cellStyleString));
    } else if (stylesTable.getNumCellStyles() > 0) {
        style = stylesTable.getStyleAt(0);
    }

    if (style != null) {
        cell.setNumericFormatIndex(style.getDataFormat());
        String formatString = style.getDataFormatString();

        if (formatString != null) {
            cell.setNumericFormat(formatString);
        } else {
            cell.setNumericFormat(BuiltinFormats.getBuiltinFormat(cell.getNumericFormatIndex()));
        }
    } else {
        cell.setNumericFormatIndex(null);
        cell.setNumericFormat(null);
    }
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:32,代码来源:StreamingSheetReader.java

示例12: addLangCell

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
private int addLangCell(Row header, TmxSegement segment) {
	int CellNum = header.getLastCellNum();
	if (-1 == CellNum) {
		CellNum = 0;
	}
	Cell createCell = header.createCell(CellNum);
	CellStyle cellStyle = wb.createCellStyle();
	XSSFFont headerFont = (XSSFFont) wb.createFont();
	headerFont.setBold(true);
	cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
	cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
	cellStyle.setFont(headerFont);
	createCell.setCellValue(segment.getLangCode());
	createCell.setCellStyle(cellStyle);
	sh.setColumnWidth(CellNum, (100 * 7 + 5) / 7 * 256);
	return CellNum;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:18,代码来源:Excel2007Writer.java

示例13: addBackgroundColourToStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
@Override
public void addBackgroundColourToStyle(Workbook workbook, CellStyle style, String colour) {
	if(colour == null) {
		return ;
	}
	if(IStyle.TRANSPARENT_VALUE.equals(colour)) {
		return ;
	}
	if(style instanceof XSSFCellStyle) {
		XSSFCellStyle cellStyle = (XSSFCellStyle)style;
		XSSFColor xColour = getXColour(colour);
		if(xColour != null) {
			cellStyle.setFillForegroundColor(xColour);
			cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		}
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:18,代码来源:StyleManagerXUtils.java

示例14: setFormatString

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * Read the numeric format string out of the styles table for this cell. Stores
 * the result in the Cell.
 *
 * @param startElement
 * @param cell
 */
void setFormatString(StartElement startElement, StreamingCell cell) {
  Attribute cellStyle = startElement.getAttributeByName(new QName("s"));
  String cellStyleString = (cellStyle != null) ? cellStyle.getValue() : null;
  XSSFCellStyle style = null;

  if(cellStyleString != null) {
    style = stylesTable.getStyleAt(Integer.parseInt(cellStyleString));
  } else if(stylesTable.getNumCellStyles() > 0) {
    style = stylesTable.getStyleAt(0);
  }

  if(style != null) {
    cell.setNumericFormatIndex(style.getDataFormat());
    String formatString = style.getDataFormatString();

    if(formatString != null) {
      cell.setNumericFormat(formatString);
    } else {
      cell.setNumericFormat(BuiltinFormats.getBuiltinFormat(cell.getNumericFormatIndex()));
    }
  } else {
    cell.setNumericFormatIndex(null);
    cell.setNumericFormat(null);
  }
}
 
开发者ID:monitorjbl,项目名称:excel-streaming-reader,代码行数:33,代码来源:StreamingSheetReader.java

示例15: styleHeader

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入依赖的package包/类
/**
 * See http://thinktibits.blogspot.co.uk/2012/12/Java-POI-XLS-XLSX-Change-Cell-Font-Color-Example.html
 * Currently only for xlsx
 * @param wb
 * @param sheet
 */
private static void styleHeader(Workbook wb, Sheet sheet){
	if(XSSFWorkbook.class.isInstance(wb) && XSSFSheet.class.isInstance(sheet)){
        XSSFWorkbook my_workbook = (XSSFWorkbook)wb; 
        XSSFCellStyle my_style = my_workbook.createCellStyle();
        XSSFFont my_font=my_workbook.createFont();
        my_font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        my_style.setFont(my_font);
        
        Row row = sheet.getRow(0);
        if(row!=null && row.getFirstCellNum()>=0){
	        for(int i = row.getFirstCellNum() ; i<= row.getLastCellNum();i++){
	        	Cell cell = row.getCell(i);
	        	if(cell!=null){
		        	cell.setCellStyle(my_style);	        		
	        	}
	        }	        	
        }
	}        
}
 
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:26,代码来源:PoiIO.java


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