EasyXLS™ library allows you to apply horizontal and vertical alignment to the text in the spreadsheet cells. The indentation, text orientation and text direction are formatting features that can also be set for Excel cells.
For better performances, the best option is to apply the alignment 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.
In EasyXLS, you can set horizontal alignment for a cell. The available horizontal alignments are General, Left, Center, Right, Fill, Justify, Center across selection and Distributed alignment. The below source code sample shows how to apply Center alignment to a cell style from the Excel file.
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_CENTER);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_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->setHorizontalAlignment(ALIGNMENT_ALIGNMENT_CENTER);
// 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->setHorizontalAlignment(Alignment::ALIGNMENT_CENTER);
// 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.setHorizontalAlignment(Alignment.ALIGNMENT_CENTER);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setHorizontalAlignment($ALIGNMENT_ALIGNMENT_CENTER);
// 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->setHorizontalAlignment($ALIGNMENT_ALIGNMENT_CENTER);
// 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.setHorizontalAlignment(ALIGNMENT_ALIGNMENT_CENTER)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_ALIGNMENT_CENTER)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setHorizontalAlignment(ALIGNMENT_ALIGNMENT_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.setHorizontalAlignment(Alignment.ALIGNMENT_CENTER)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_CENTER)
# 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.setHorizontalAlignment(gateway.jvm.Alignment.ALIGNMENT_CENTER)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Click here to see Continuous Code Listing
In EasyXLS, you can set vertical alignment for a cell. The available vertical alignments are Top, Middle, Bottom, Justify and Distributed alignment. The below source code sample shows how to apply Bottom alignment to a cell style from the Excel file.
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setVerticalAlignment(Alignment.ALIGNMENT_BOTTOM);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
xlsStyle.setVerticalAlignment(Alignment.ALIGNMENT_BOTTOM)
' 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->setVerticalAlignment(ALIGNMENT_ALIGNMENT_BOTTOM);
// 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->setVerticalAlignment(Alignment::ALIGNMENT_BOTTOM);
// 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.setVerticalAlignment(Alignment.ALIGNMENT_BOTTOM);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setVerticalAlignment($ALIGNMENT_ALIGNMENT_BOTTOM);
// 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->setVerticalAlignment($ALIGNMENT_ALIGNMENT_BOTTOM);
// 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.setVerticalAlignment(ALIGNMENT_ALIGNMENT_BOTTOM)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setVerticalAlignment(Alignment.ALIGNMENT_ALIGNMENT_BOTTOM)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setVerticalAlignment(ALIGNMENT_ALIGNMENT_BOTTOM)
' 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.setVerticalAlignment(Alignment.ALIGNMENT_BOTTOM)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setVerticalAlignment(Alignment.ALIGNMENT_BOTTOM)
# 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.setVerticalAlignment(gateway.jvm.Alignment.ALIGNMENT_BOTTOM)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Click here to see Continuous Code Listing
The indentation is available for specific horizontal alignments like Left, Right and Distributed alignment. The below source code sample shows how to set indentation for a cell style from the Excel file.
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT);
xlsStyle.setIndent(2);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As New ExcelStyle()
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT)
xlsStyle.setIndent(2)
' 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->setHorizontalAlignment(ALIGNMENT_ALIGNMENT_LEFT);
xlsStyle->setIndent(2);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
C++.NET// Create a style for the cell
ExcelStyle ^xlsStyle = gcnew ExcelStyle();
xlsStyle->setHorizontalAlignment(Alignment::ALIGNMENT_LEFT);
xlsStyle->setIndent(2);
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT);
xlsStyle.setIndent(2);
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
COM+:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setHorizontalAlignment($ALIGNMENT_ALIGNMENT_LEFT);
$xlsStyle->setIndent(2);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
Java:// Create a style for the cell
$xlsStyle = new java("EasyXLS.ExcelStyle");
$xlsStyle->setHorizontalAlignment($ALIGNMENT_ALIGNMENT_LEFT);
$xlsStyle->setIndent(2);
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
' Create a style for the cellset xlsStyle = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setHorizontalAlignment(ALIGNMENT_ALIGNMENT_LEFT)
xlsStyle.setIndent(2)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_ALIGNMENT_LEFT)
xlsStyle.setIndent(2)
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setHorizontalAlignment(ALIGNMENT_ALIGNMENT_LEFT)
xlsStyle.setIndent(2)
' 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.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT)><cfset xlsStyle.setIndent(2)><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT)
xlsStyle.setIndent(2)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Java:# Create a style for the cell
xlsStyle = gateway.jvm.ExcelStyle()
xlsStyle.setHorizontalAlignment(gateway.jvm.Alignment.ALIGNMENT_LEFT)
xlsStyle.setIndent(2)
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)