本文整理了Java中org.apache.poi.ss.usermodel.CellStyle.setFillBackgroundColor()
方法的一些代码示例,展示了CellStyle.setFillBackgroundColor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CellStyle.setFillBackgroundColor()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.CellStyle
类名称:CellStyle
方法名:setFillBackgroundColor
[英]set the background fill color.
[中]设置背景填充颜色。
代码示例来源:origin: stackoverflow.com
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
row.setRowStyle(style);
代码示例来源:origin: stackoverflow.com
Workbook wb = new XSSFWorkbook("myWorkbook.xlsx");
Row row=sheet.getRow(0);
CellStyle style=null;
XSSFFont defaultFont= wb.createFont();
defaultFont.setFontHeightInPoints((short)10);
defaultFont.setFontName("Arial");
defaultFont.setColor(IndexedColors.BLACK.getIndex());
defaultFont.setBold(false);
defaultFont.setItalic(false);
XSSFFont font= wb.createFont();
font.setFontHeightInPoints((short)10);
font.setFontName("Arial");
font.setColor(IndexedColors.WHITE.getIndex());
font.setBold(true);
font.setItalic(false);
style=row.getRowStyle();
style.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFont(font);
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
@Override
public CellStyle headCellStyle(SXSSFWorkbook wb) {
CellStyle cellStyle = wb.createCellStyle();
Font font = wb.createFont();
cellStyle.setFillForegroundColor((short) 12);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);// 填充模式
cellStyle.setBorderTop(CellStyle.BORDER_THIN);// 上边框为细边框
cellStyle.setBorderRight(CellStyle.BORDER_THIN);// 右边框为细边框
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);// 下边框为细边框
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);// 左边框为细边框
cellStyle.setAlignment(CellStyle.ALIGN_LEFT);// 对齐
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillBackgroundColor(HSSFColor.GREEN.index);
font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
// font.setFontHeightInPoints((short) 12);// 字体大小
font.setColor(HSSFColor.WHITE.index);
// 应用标题字体到标题样式
cellStyle.setFont(font);
return cellStyle;
}
代码示例来源:origin: org.apache.poi/poi
/**
* Sets the format properties of the given style based on the given map.
*
* @param style cell style
* @param workbook parent workbook
* @param properties map of format properties (String -> Object)
* @see #getFormatProperties(CellStyle)
*/
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
style.setDataFormat(getShort(properties, DATA_FORMAT));
style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
style.setFont(workbook.getFontAt(getInt(properties, FONT)));
style.setHidden(getBoolean(properties, HIDDEN));
style.setIndention(getShort(properties, INDENTION));
style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
style.setLocked(getBoolean(properties, LOCKED));
style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
style.setRotation(getShort(properties, ROTATION));
style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
style.setWrapText(getBoolean(properties, WRAP_TEXT));
}
代码示例来源:origin: Vatavuk/excel-io
@Override
public void accept(final CellStyle style) {
style.setFillBackgroundColor(this.color);
}
}
代码示例来源:origin: FenixEdu/fenixedu-academic
protected CellStyle headerBackgroundStyle() {
CellStyle style = workbook.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
return style;
}
代码示例来源:origin: FenixEdu/fenixedu-academic
private CellStyle headerBackgroundStyle(final HSSFWorkbook wb) {
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(FillPatternType.BIG_SPOTS);
return style;
}
代码示例来源:origin: stackoverflow.com
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow((short) 1);
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
Cell cell = row.createCell((short) 1);
cell.setCellValue("X");
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
cell = row.createCell((short) 2);
cell.setCellValue("X");
cell.setCellStyle(style);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
代码示例来源:origin: stackoverflow.com
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow((short) 1);
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
Cell cell = row.createCell((short) 1);
cell.setCellValue("X");
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
cell = row.createCell((short) 2);
cell.setCellValue("X");
cell.setCellStyle(style);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
代码示例来源:origin: cyuanxin/excel_export_import
private static void createTitleRow(Workbook workbook, Row row, List<ExportCell> exportCells, Sheet sheet) {
CellStyle style = createHeadStyle(workbook);
row.setHeightInPoints(25.0F);
Font font = workbook.createFont();
font.setColor((short) 12);
// font.setBoldweight((short) 700);
style.setFont(font);
style.setFillBackgroundColor((short) 13);
int i = 0;
for (ExportCell exportCell : exportCells) {
sheet.setColumnWidth(i, 3200);
Cell cell = row.createCell(i);
cell.setCellValue(exportCell.getTitle());
cell.setCellStyle(style);
++i;
}
}
代码示例来源:origin: stackoverflow.com
estiloCabecera.setFillBackgroundColor(IndexedColors.BLACK.getIndex());
estiloCabecera.setFillPattern(CellStyle.SOLID_FOREGROUND);
代码示例来源:origin: org.apache.poi/poi-examples
public static void main(String[] args) throws IOException {
try (Workbook wb = new XSSFWorkbook()) { //or new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow(1);
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(FillPatternType.BIG_SPOTS);
Cell cell = row.createCell(1);
cell.setCellValue(new XSSFRichTextString("X"));
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell = row.createCell(2);
cell.setCellValue(new XSSFRichTextString("X"));
cell.setCellStyle(style);
// Write the output to a file
try (FileOutputStream fileOut = new FileOutputStream("fill_colors.xlsx")) {
wb.write(fileOut);
}
}
}
}
代码示例来源:origin: stackoverflow.com
CellStyle backgroundStyle = workbook.createCellStyle();
backgroundStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
backgroundStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
backgroundStyle.setBorderBottom(CellStyle.BORDER_THIN);
backgroundStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
backgroundStyle.setBorderLeft(CellStyle.BORDER_THIN);
backgroundStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
backgroundStyle.setBorderRight(CellStyle.BORDER_THIN);
backgroundStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
backgroundStyle.setBorderTop(CellStyle.BORDER_THIN);
backgroundStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
代码示例来源:origin: stackoverflow.com
CellStyle backgroundStyle = workbook.createCellStyle();
backgroundStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
backgroundStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
CellStyle borderStyle = workbook.createCellStyle();
borderStyle.setBorderBottom(CellStyle.BORDER_THIN);
borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
borderStyle.setBorderLeft(CellStyle.BORDER_THIN);
borderStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
borderStyle.setBorderRight(CellStyle.BORDER_THIN);
borderStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
borderStyle.setBorderTop(CellStyle.BORDER_THIN);
borderStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
代码示例来源:origin: com.helger/ph-poi
public void fillCellStyle (@Nonnull final Workbook aWB,
@Nonnull final CellStyle aCS,
@Nonnull final CreationHelper aCreationHelper)
{
if (m_eAlign != null)
aCS.setAlignment (m_eAlign);
if (m_eVAlign != null)
aCS.setVerticalAlignment (m_eVAlign);
aCS.setWrapText (m_bWrapText);
if (m_sDataFormat != null)
aCS.setDataFormat (aCreationHelper.createDataFormat ().getFormat (m_sDataFormat));
if (m_eFillBackgroundColor != null)
aCS.setFillBackgroundColor (m_eFillBackgroundColor.getIndex ());
if (m_eFillForegroundColor != null)
aCS.setFillForegroundColor (m_eFillForegroundColor.getIndex ());
if (m_eFillPattern != null)
aCS.setFillPattern (m_eFillPattern);
if (m_eBorderTop != null)
aCS.setBorderTop (m_eBorderTop);
if (m_eBorderRight != null)
aCS.setBorderRight (m_eBorderRight);
if (m_eBorderBottom != null)
aCS.setBorderBottom (m_eBorderBottom);
if (m_eBorderLeft != null)
aCS.setBorderLeft (m_eBorderLeft);
if (m_nFontIndex >= 0)
aCS.setFont (aWB.getFontAt (m_nFontIndex));
}
代码示例来源:origin: wuyouzhuguli/FEBS-Security
@Override
public CellStyle headCellStyle(SXSSFWorkbook wb) {
CellStyle cellStyle = wb.createCellStyle();
Font font = wb.createFont();
cellStyle.setFillForegroundColor((short) 12);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);// 填充模式
cellStyle.setBorderTop(CellStyle.BORDER_THIN);// 上边框为细边框
cellStyle.setBorderRight(CellStyle.BORDER_THIN);// 右边框为细边框
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);// 下边框为细边框
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);// 左边框为细边框
cellStyle.setAlignment(CellStyle.ALIGN_LEFT);// 对齐
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillBackgroundColor(HSSFColor.GREEN.index);
font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
// font.setFontHeightInPoints((short) 12);// 字体大小
font.setColor(HSSFColor.WHITE.index);
// 应用标题字体到标题样式
cellStyle.setFont(font);
return cellStyle;
}
代码示例来源:origin: eu.ralph-schuster/csv
/**
* Applies the style to the cell.
* @param style the style to be set from this description
*/
public void applyStyle(CellStyle style) {
if (format != null) style.setDataFormat(format);
if (fgColor != null) {
style.setFillForegroundColor(fgColor);
if (fillPattern != null) style.setFillPattern(fillPattern);
}
if (bgColor != null) style.setFillBackgroundColor(bgColor);
if (font != null) style.setFont(font);
if (alignment != null) style.setAlignment(alignment);
// Borders;
if (topBorderColor != null) style.setTopBorderColor(topBorderColor);
if (leftBorderColor != null) style.setLeftBorderColor(leftBorderColor);
if (rightBorderColor != null) style.setRightBorderColor(rightBorderColor);
if (bottomBorderColor != null) style.setBottomBorderColor(bottomBorderColor);
if (topBorderThickness != null) style.setBorderTop(topBorderThickness);
if (leftBorderThickness != null) style.setBorderLeft(leftBorderThickness);
if (rightBorderThickness != null) style.setBorderRight(rightBorderThickness);
if (bottomBorderThickness != null) style.setBorderBottom(bottomBorderThickness);
style.setWrapText(isTextWrap());
}
代码示例来源:origin: wuwz/ExcelKit
public CellStyle getHeaderCellStyle(SXSSFWorkbook wb) {
if (null == mHeaderCellStyle) {
mHeaderCellStyle = wb.createCellStyle();
Font font = wb.createFont();
mHeaderCellStyle.setFillForegroundColor((short) 12);
mHeaderCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
mHeaderCellStyle.setBorderTop(BorderStyle.DOTTED);
mHeaderCellStyle.setBorderRight(BorderStyle.DOTTED);
mHeaderCellStyle.setBorderBottom(BorderStyle.DOTTED);
mHeaderCellStyle.setBorderLeft(BorderStyle.DOTTED);
mHeaderCellStyle.setAlignment(HorizontalAlignment.LEFT);// 对齐
mHeaderCellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
mHeaderCellStyle.setFillBackgroundColor(HSSFColor.GREEN.index);
font.setColor(HSSFColor.WHITE.index);
// 应用标题字体到标题样式
mHeaderCellStyle.setFont(font);
//设置单元格文本形式
DataFormat dataFormat = wb.createDataFormat();
mHeaderCellStyle.setDataFormat(dataFormat.getFormat("@"));
}
return mHeaderCellStyle;
}
}
代码示例来源:origin: com.haulmont.thirdparty/poi
/**
* Sets the format properties of the given style based on the given map.
*
* @param style cell style
* @param workbook parent workbook
* @param properties map of format properties (String -> Object)
* @see #getFormatProperties(CellStyle)
*/
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
style.setAlignment(getShort(properties, ALIGNMENT));
style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
style.setBorderLeft(getShort(properties, BORDER_LEFT));
style.setBorderRight(getShort(properties, BORDER_RIGHT));
style.setBorderTop(getShort(properties, BORDER_TOP));
style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
style.setDataFormat(getShort(properties, DATA_FORMAT));
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
style.setFillPattern(getShort(properties, FILL_PATTERN));
style.setFont(workbook.getFontAt(getShort(properties, FONT)));
style.setHidden(getBoolean(properties, HIDDEN));
style.setIndention(getShort(properties, INDENTION));
style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
style.setLocked(getBoolean(properties, LOCKED));
style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
style.setRotation(getShort(properties, ROTATION));
style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
style.setWrapText(getBoolean(properties, WRAP_TEXT));
}
代码示例来源:origin: com.eas.platypus/platypus-js-reports
private void copyStyle(Workbook workbook, Cell fromCell, Cell toCell) {
CellStyle toStyle = toCell.getCellStyle();
CellStyle fromStyle = fromCell.getCellStyle();
CellStyle newStyle = workbook.createCellStyle();
newStyle.setAlignment(fromStyle.getAlignment());
newStyle.setBorderBottom(fromStyle.getBorderBottom());
newStyle.setBorderLeft(fromStyle.getBorderLeft());
newStyle.setBorderRight(fromStyle.getBorderRight());
newStyle.setBorderTop(fromStyle.getBorderTop());
newStyle.setBottomBorderColor(fromStyle.getBottomBorderColor());
newStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor());
newStyle.setFillForegroundColor(fromStyle.getFillForegroundColor());
newStyle.setFillPattern(fromStyle.getFillPattern());
newStyle.setFont(workbook.getFontAt(fromStyle.getFontIndex()));
newStyle.setHidden(fromStyle.getHidden());
newStyle.setIndention(fromStyle.getIndention());
newStyle.setLeftBorderColor(fromStyle.getLeftBorderColor());
newStyle.setLocked(fromStyle.getLocked());
newStyle.setRightBorderColor(fromStyle.getRightBorderColor());
newStyle.setTopBorderColor(fromStyle.getTopBorderColor());
newStyle.setVerticalAlignment(fromStyle.getVerticalAlignment());
newStyle.setWrapText(fromStyle.getWrapText());
newStyle.setDataFormat(toStyle.getDataFormat());
toCell.setCellStyle(newStyle);
}
}
内容来源于网络,如有侵权,请联系作者删除!