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


Java XSSFCellStyle.setFillForegroundColor方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: createHeaderStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
public static CellStyle createHeaderStyle(Workbook workbook) {
    XSSFCellStyle headerStyle = createCellStyle(workbook);
    XSSFColor header = new XSSFColor(new byte[]{(byte) 79, (byte) 129, (byte) 189});
    headerStyle.setFillForegroundColor(header);
    headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    headerStyle.getFont().setColor(IndexedColors.WHITE.index);
    return headerStyle;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:aem-epic-tool,代码行数:9,代码来源:ReportUtil.java

示例7: exportExcelTemplate

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的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

示例8: createXSSFCellStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的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

示例9: createTitleXSSFCellStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
public static XSSFCellStyle createTitleXSSFCellStyle(XSSFWorkbook wb){
	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(new XSSFColor( new Color(75, 172, 198)));
	cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
	return cellStyle;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport2.0,代码行数:16,代码来源:XSSFCellUtil.java

示例10: applyColor

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
private static void applyColor(Workbook createNewWorkBookXlsx, ExcelColDVO dvo, Cell createCell) {
	Color backgroundColor = dvo.getBackgroundColor();
	if (backgroundColor != null) {
		XSSFCellStyle style = (XSSFCellStyle) createNewWorkBookXlsx.createCellStyle();
		style.setFillPattern(CellStyle.SOLID_FOREGROUND);
		style.setFillForegroundColor(new XSSFColor(backgroundColor));
		createCell.setCellStyle(style);
	}
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:10,代码来源:ExcelUtil.java

示例11: getHeadStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
 * 设置表头的单元格样式
 * 
 * @return
 */
public XSSFCellStyle getHeadStyle() {
	// 创建单元格样式
	XSSFCellStyle cellStyle = wb.createCellStyle();
	// 设置单元格的背景颜色为淡蓝色
	cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
	// 创建单元格内容显示不下时自动换行
	//cellStyle.setWrapText(true);
	// 设置单元格字体样式
	XSSFFont font = wb.createFont();
	// 设置字体加粗
	font.setFontName("宋体");
	font.setFontHeight((short) 200);
	cellStyle.setFont(font);
	return cellStyle;
}
 
开发者ID:roncoo,项目名称:roncoo-jui-springboot,代码行数:21,代码来源:ExcelUtil.java

示例12: customStyleWorkbook

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
@Test
public void customStyleWorkbook() {
  Workbook wb = new XSSFWorkbook();
  
  Table table = new Table();
  table.addHeader(new ExcelCell("ID"));
  table.addHeader(new ExcelCell("NOM"));
  table.addHeader(new ExcelCell("TITRE"));

  XSSFCellStyle cs = (XSSFCellStyle) wb.createCellStyle();
  cs.setFillForegroundColor(StyleHelper.getColor(128, 100, 162));
  cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
  table.setPosition("A1");
  table.addData(new ExcelRow(new ExcelCell("1"), new ExcelCell("Henri Loevenbruck"), new ExcelCell("L'apothicaire")));
  table.addData(new ExcelRow(new ExcelCell(2), new ExcelCell("Cyril Massarotto"), new ExcelCell("Dieu est un pote à moi")));
  table.addData(new ExcelRow(new ExcelCell(3), new ExcelCell("Bernard Werber"), new ExcelCell("Les fourmis")));
  table.addData(new ExcelRow(new ExcelCell(4, cs), new ExcelCell("Maxime Chattam"), new ExcelCell("In Tenebris")));
  table.addData(new ExcelRow(new ExcelCell(5), new ExcelCell("Franck Thilliez"), new ExcelCell("Pandemia")));

  PoiLight.createTable(wb, table);

  String excelFilename = TestHelper.getFullPath("CustomStyleWorkbook.xlsx");
  PoiLight.writeExcel(wb, excelFilename);

  try {
    wb = new XSSFWorkbook(excelFilename);
    Sheet sheet = wb.getSheet(PoiLightConst.DEFAULT_SHEET_NAME);
    Row row = sheet.getRow(4);
    Cell cell = row.getCell(0);
    XSSFCellStyle csValue = (XSSFCellStyle) cell.getCellStyle();
    assertEquals(CellStyle.SOLID_FOREGROUND, csValue.getFillPattern());
    assertEquals(StyleHelper.getColor(128, 100, 162), csValue.getFillForegroundXSSFColor()); 

    wb.close();
  } catch (IOException exception) {
    exception.printStackTrace();
    assertFalse(true);
  }

}
 
开发者ID:lynchmaniac,项目名称:poilight,代码行数:41,代码来源:PoiLightTest.java

示例13: createHeaderStyle

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
CellStyle createHeaderStyle(Workbook wb){
    XSSFCellStyle xstyle = (XSSFCellStyle)wb.createCellStyle();
    XSSFColor header = new XSSFColor(new byte[]{(byte)79, (byte)129, (byte)189} );
    xstyle.setFillForegroundColor(header);
    xstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    XSSFFont font = (XSSFFont)wb.createFont();
    font.setColor(IndexedColors.WHITE.index);
    xstyle.setFont(font);
    return xstyle;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:11,代码来源:GenericReportExcelServlet.java

示例14: createXSSFCellStyles

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的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

示例15: defaultForeGround

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
private void defaultForeGround(XSSFCellStyle style) {
	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
	style.setFillForegroundColor(DEFAULT_HEADER_FOREGROUND_COLOR);
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:5,代码来源:FxExcelUtil.java


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