EasyXLS™ library enables you to apply a background for Excel cells, rows, and columns. Background color, patterns and fill effects can be set for the Excel spreadsheet.
For better performances, the best option is to apply the background setting to the style of the cell, row, or column by using ExcelStyle class. But the formatting can also be applied directly to the cell, row, or column.
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setBackground(Color.Black);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
xlsStyle.setBackground(Color.Black)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
C++// Create a style for the cell
EasyXLS::IExcelStylePtr xlsStyle;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**) &xlsStyle);
xlsStyle->setBackground(COLOR_BLACK);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
Click here to see Continuous Code ListingC++.NET// Create a style for the cell
ExcelStyle ^xlsStyle = gcnew ExcelStyle();
xlsStyle->setBackground(Color::Black);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
Click here to see Continuous Code Listing
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setBackground(Color.BLACK);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setBackground((int)$COLOR_BLACK);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
Click here to see Continuous Code ListingJava:// Create a style for the cell
$xlsStyle = new java("EasyXLS.ExcelStyle");
$xlsStyle->setBackground(java("java.awt.Color")->BLACK);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
Click here to see Continuous Code Listing
' Create a style for the cellset xlsStyle = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setBackground(CLng(COLOR_BLACK))
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setBackground(CLng(Color.COLOR_BLACK))
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setBackground(CLng(BLACK))
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
<!-- Create a style for the cell --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyle"action="CREATE">
<cfset xlsStyle.setBackground(Color.black)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setBackground(Color.Black)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Click here to see Continuous Code ListingJava:# Create a style for the cell
xlsStyle = gateway.jvm.ExcelStyle()
xlsStyle.setBackground(gateway.jvm.Color.BLACK)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Click here to see Continuous Code Listing
Above the cell background, various pattern styles can be applied. The below source code sample shows how to apply a pattern for a cell style from the Excel file.
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
// Set pattern
xlsStyle.setPattern(Pattern.PATTERN_HORIZONTAL_STRIPE);
// Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(Color.Red);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
' Set pattern
xlsStyle.setPattern(Pattern.PATTERN_HORIZONTAL_STRIPE)
' Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(Color.Red)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
C++// Create a style for the cell
EasyXLS::IExcelStylePtr xlsStyle;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**) &xlsStyle);
// Set pattern
xlsStyle->setPattern(PATTERN_PATTERN_HORIZONTAL_STRIPE);
// Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(COLOR_RED);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
C++.NET// Create a style for the cell
ExcelStyle ^xlsStyle = gcnew ExcelStyle();
// Set pattern
xlsStyle->setPattern(Pattern::PATTERN_HORIZONTAL_STRIPE);
// Optionally, the default pattern color can be changed
xlsStyle->setPatternColor(Color::Red);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
// Set pattern
xlsStyle.setPattern(Pattern.PATTERN_HORIZONTAL_STRIPE);
// Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(Color.RED);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
// Set pattern
$xlsStyle->setPattern($PATTERN_PATTERN_HORIZONTAL_STRIPE);
// Optionally, the default pattern color can be changed
$xlsStyle->setPatternColor((int)$COLOR_RED);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
Java:// Create a style for the cell
$xlsStyle = new java("EasyXLS.ExcelStyle");
// Set pattern
$xlsStyle->setPattern($PATTERN_PATTERN_HORIZONTAL_STRIPE);
// Optionally, the default pattern color can be changed
$xlsStyle->setPatternColor(java("java.awt.Color")->RED);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
' Create a style for the cellset xlsStyle = Server.CreateObject("EasyXLS.ExcelStyle")
' Set pattern
xlsStyle.setPattern(PATTERN_PATTERN_HORIZONTAL_STRIPE)
' Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(CLng(COLOR_RED))
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
' Set pattern
xlsStyle.setPattern(Pattern.PATTERN_PATTERN_HORIZONTAL_STRIPE)
' Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(CLng(Color.COLOR_RED))
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
' Set pattern
xlsStyle.setPattern(PATTERN_HORIZONTAL_STRIPE)
' Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(CLng(RED))
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
<!-- Create a style for the cell --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyle"action="CREATE">
<!-- Set pattern --><cfset xlsStyle.setPattern(Pattern.PATTERN_HORIZONTAL_STRIPE)><!-- Optionally, the default pattern color can be changed --><cfset xlsStyle.setPatternColor(Color.red)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
# Set pattern
xlsStyle.setPattern(Pattern.PATTERN_HORIZONTAL_STRIPE)
# Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(Color.Red)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Java:# Create a style for the cell
xlsStyle = gateway.jvm.ExcelStyle()
# Set pattern
xlsStyle.setPattern(gateway.jvm.Pattern.PATTERN_HORIZONTAL_STRIPE)
# Optionally, the default pattern color can be changed
xlsStyle.setPatternColor(gateway.jvm.Color.RED)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setGradientFill(Color.White, Color.Black, Fill.GRADIENT_FROM_CENTER);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
xlsStyle.setGradientFill(Color.White, Color.Black, Fill.GRADIENT_FROM_CENTER)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
C++// Create a style for the cell
EasyXLS::IExcelStylePtr xlsStyle;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**) &xlsStyle);
xlsStyle.setGradientFill(COLOR_WHITE, COLOR_BLACK, FILL_GRADIENT_GRADIENT_FROM_CENTER);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
C++.NET// Create a style for the cell
ExcelStyle ^xlsStyle = gcnew ExcelStyle();
xlsStyle->setGradientFill(Color::White, Color::Black, Fill::GRADIENT_FROM_CENTER);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setGradientFill(Color.WHITE, Color.BLACK, Fill.GRADIENT_FROM_CENTER);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setGradientFill((int)$COLOR_WHITE, (int)$COLOR_BLACK,
$FILL_GRADIENT_GRADIENT_FROM_CENTER);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
Java:// Create a style for the cell
$xlsStyle = new java("EasyXLS.ExcelStyle");
$xlsStyle->setGradientFill(java("java.awt.Color")->WHITE,
java("java.awt.Color")->BLACK, $FILL_GRADIENT_GRADIENT_FROM_CENTER);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
' Create a style for the cellset xlsStyle = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setGradientFill(CLng(COLOR_WHITE), CLng(COLOR_BLACK), _
FILL_GRADIENT_GRADIENT_FROM_CENTER)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setGradientFill CLng(Color.COLOR_WHITE), CLng(Color.COLOR_BLACK), _
Fill.FILL_GRADIENT_GRADIENT_FROM_CENTER
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setGradientFill CLng(WHITE), CLng(BLACK), FILL_GRADIENT_GRADIENT_FROM_CENTER
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
<!-- Create a style for the cell --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyle"action="CREATE">
<cfset xlsStyle.setGradientFill(Color.white, Color.black, Fill.GRADIENT_FROM_CENTER)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setGradientFill(Color.White, Color.Black, Fill.GRADIENT_FROM_CENTER)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Java:# Create a style for the cell
xlsStyle = gateway.jvm.ExcelStyle()
xlsStyle.setGradientFill(gateway.jvm.Color.WHITE , gateway.jvm.Color.BLACK ,
gateway.jvm.Fill.GRADIENT_FROM_CENTER)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)