EasyXLS™ library enables you to apply borders around the Excel cells, rows, and columns or diagonal borders. A variety of border styles and border colors can be set for the spreadsheet cells.
For better performances, the best option is to apply the border 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.
EasyXLS provides multiple predefined border styles. The below source code sample shows how to apply top and bottom borders for a cell style from the Excel file. The gray color is set for the borders.
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setBorderStyles(Border.BORDER_MEDIUM, Border.BORDER_MEDIUM,
Border.BORDER_NONE, Border.BORDER_NONE);
xlsStyle.setBorderColors(Color.Gray, Color.Gray, Color.Empty, Color.Empty);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
xlsStyle.setBorderStyles(Border.BORDER_MEDIUM, Border.BORDER_MEDIUM,
Border.BORDER_NONE, Border.BORDER_NONE)
xlsStyle.setBorderColors(Color.Gray, Color.Gray, Color.Empty, Color.Empty)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
C++
#define COLOR_GRAY 0xff808080
#define COLOR_NONE 0x00000000
...
// Create a style for the cell
EasyXLS::IExcelStylePtr xlsStyle;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**) &xlsStyle);
xlsStyle->setBorderStyles(BORDER_BORDER_MEDIUM, BORDER_BORDER_MEDIUM,
BORDER_BORDER_NONE, BORDER_BORDER_NONE);
xlsStyle->setBorderColors(COLOR_GRAY, COLOR_GRAY, COLOR_NONE, COLOR_NONE);
// 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->setBorderStyles(Border::BORDER_MEDIUM, Border::BORDER_MEDIUM,
Border::BORDER_NONE, Border::BORDER_NONE);
xlsStyle->setBorderColors(Color::Gray, Color::Gray, Color::Empty, Color::Empty);
// 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.setBorderStyles(Border.BORDER_MEDIUM, Border.BORDER_MEDIUM,
Border.BORDER_NONE, Border.BORDER_NONE);
xlsStyle.setBorderColors(Color.GRAY, Color.GRAY, null, null);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setBorderStyles($BORDER_BORDER_MEDIUM, $BORDER_BORDER_MEDIUM,
$BORDER_BORDER_NONE, $BORDER_BORDER_NONE);
$xlsStyle->setBorderColors((int)$COLOR_GRAY, (int)$COLOR_GRAY,
(int)$COLOR_NONE, (int)$COLOR_NONE);
// 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->setBorderStyles($BORDER_BORDER_MEDIUM, $BORDER_BORDER_MEDIUM,
$BORDER_BORDER_NONE, $BORDER_BORDER_NONE);
$xlsStyle->setBorderColors(java("java.awt.Color")->GRAY, java("java.awt.Color")->GRAY,
null, null);
// 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.setBorderStyles BORDER_BORDER_MEDIUM, BORDER_BORDER_MEDIUM, _
BORDER_BORDER_NONE, BORDER_BORDER_NONE
xlsStyle.setBorderColors CLng(COLOR_GRAY), CLng(COLOR_GRAY), _
CLng(COLOR_NONE), CLng(COLOR_NONE)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setBorderStyles Border.BORDER_BORDER_MEDIUM, Border.BORDER_BORDER_MEDIUM, _
Border.BORDER_BORDER_NONE, Border.BORDER_BORDER_NONE
xlsStyle.setBorderColors CLng(Color.COLOR_GRAY), CLng(Color.COLOR_GRAY), _
CLng(Color.COLOR_NONE), CLng(Color.COLOR_NONE)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Dim COLOR_NONE
COLOR_NONE = &h00000000
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setBorderStyles BORDER_MEDIUM, BORDER_MEDIUM, BORDER_NONE, BORDER_NONE
xlsStyle.setBorderColors CLng(GRAY), CLng(GRAY), CLng(NONE), CLng(NONE)
' 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.setBorderStyles(Border.BORDER_MEDIUM, Border.BORDER_MEDIUM,
Border.BORDER_NONE, Border.BORDER_NONE)><cfobject type="java"class="java.awt.Color"name="colorNull"action="CREATE">
<cfset xlsStyle.setBorderColors(Color.gray, Color.gray, colorNull, colorNull)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setBorderStyles(Border.BORDER_MEDIUM, Border.BORDER_MEDIUM,
Border.BORDER_NONE, Border.BORDER_NONE)
xlsStyle.setBorderColors(Color.Gray, Color.Gray, Color.Empty, Color.Empty)
# 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.setBorderStyles(gateway.jvm.Border.BORDER_MEDIUM,
gateway.jvm.Border.BORDER_MEDIUM,
gateway.jvm.Border.BORDER_NONE,
gateway.jvm.Border.BORDER_NONE)
xlsStyle.setBorderColors(gateway.jvm.Color.GRAY, gateway.jvm.Color.GRAY, None, None)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Click here to see Continuous Code Listing
EasyXLS allows you to set diagonal borders for cells. The below source code sample shows how to apply diagonal borders for a cell style from the Excel file. The gray color is set for the borders.
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setDiagonalBorder(true, true, Border.BORDER_MEDIUM, Color.Gray);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
xlsStyle.setDiagonalBorder(true, true, Border.BORDER_MEDIUM, Color.Gray)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
C++
#define COLOR_GRAY 0xff808080
...
// Create a style for the cell
EasyXLS::IExcelStylePtr xlsStyle;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**) &xlsStyle);
xlsStyle->setDiagonalBorder(true, true, BORDER_BORDER_MEDIUM, COLOR_GRAY);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
C++.NET// Create a style for the cell
ExcelStyle ^xlsStyle = gcnew ExcelStyle();
xlsStyle->setDiagonalBorder(true, true, Border::BORDER_MEDIUM, Color::Gray);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setDiagonalBorder(true, true, Border.BORDER_MEDIUM, Color.GRAY);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setDiagonalBorder(true, true, $BORDER_BORDER_MEDIUM, (int)$COLOR_GRAY);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
Java:// Create a style for the cell
$xlsStyle = new java("EasyXLS.ExcelStyle");
$xlsStyle->setDiagonalBorder(true, true, $BORDER_BORDER_MEDIUM,
java("java.awt.Color")->GRAY);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
' Create a style for the cellset xlsStyle = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setDiagonalBorder true, true, BORDER_BORDER_MEDIUM, CLng(COLOR_GRAY)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setDiagonalBorder true, true, Border.BORDER_BORDER_MEDIUM, _
CLng(Color.COLOR_GRAY)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setDiagonalBorder true, true, BORDER_MEDIUM, CLng(GRAY)
' 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.setDiagonalBorder(true, true, Border.BORDER_MEDIUM, Color.gray)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setDiagonalBorder(True, True, Border.BORDER_MEDIUM, Color.Gray)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Java:# Create a style for the cell
xlsStyle = gateway.jvm.ExcelStyle()
xlsStyle.setDiagonalBorder(True, True, gateway.jvm.Border.BORDER_MEDIUM,
gateway.jvm.Color.GRAY)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)