EasyXLS™ library enables you to apply number formats, date and time formats, accounting formats, text formats or custom formats for values inside the spreadsheet cells. The format can be set per cell, per row and per column.
For better performances, the best option is to apply the format 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.setFormat("$0.00");
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
' Create a style for the cellDim xlsStyle As ExcelStyle = New ExcelStyle()
xlsStyle.setFormat("$0.00")
' 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->setFormat("$0.00");
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
C++.NET// Create a style for the cell
ExcelStyle ^xlsStyle = gcnew ExcelStyle();
xlsStyle->setFormat("$0.00");
// Apply the style to the cell
xlsCell->setStyle(xlsStyle);
// Create a style for the cell
ExcelStyle xlsStyle = new ExcelStyle();
xlsStyle.setFormat("$0.00");
// Apply the style to the cell
xlsCell.setStyle(xlsStyle);
.NET:// Create a style for the cell
$xlsStyle = new COM("EasyXLS.ExcelStyle");
$xlsStyle->setFormat("$0.00");
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
Java:// Create a style for the cell
$xlsStyle = new java("EasyXLS.ExcelStyle");
$xlsStyle->setFormat("$0.00");
// Apply the style to the cell
$xlsCell->setStyle($xlsStyle);
' Create a style for the cellset xlsStyle = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setFormat("$0.00")
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellSet xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setFormat("$0.00")
' Apply the style to the cell
xlsCell.setStyle(xlsStyle)
' Create a style for the cellset xlsStyle = CreateObject("EasyXLS.ExcelStyle")
xlsStyle.setFormat("$0.00")
' 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.setFormat("$0.00")><!-- Apply the style to the cell --><cfset xlsCell.setStyle(xlsStyle)>
.NET:# Create a style for the cell
xlsStyle = ExcelStyle()
xlsStyle.setFormat("$0.00")
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
Java:# Create a style for the cell
xlsStyle = gateway.jvm.ExcelStyle()
xlsStyle.setFormat("$0.00")
# Apply the style to the cell
xlsCell.setStyle(xlsStyle)
The number format includes 1000 separator, decimal separator, decimal places and the aspect for negative numbers. The 1000 separator must be always set as "," and decimal separator as ".". The regional settings from the machine are used when the Excel file is opened, and the separators set in Control Panel define the displayed separators on screen.
The below source code sample shows how to set number format for integer numbers, decimal numbers and negative numbers.
// Apply integer format
ExcelStyle xlsStyleInteger = new ExcelStyle();
xlsStyleInteger.setFormat(Format.FORMAT_INTEGER);
xlsCell.setStyle(xlsStyleInteger);
// Apply decimal format
ExcelStyle xlsStyleDecimals = new ExcelStyle();
xlsStyleDecimals.setFormat(Format.FORMAT_FLOAT_2DECIMALS);
xlsCell.setStyle(xlsStyleDecimals);
// Format with red color for negative numbers
ExcelStyle xlsStyleNegative = new ExcelStyle();
xlsStyleNegative.setFormat("0.00_);[Red](0.00)");
xlsCell.setStyle(xlsStyleNegative);
' Apply integer formatDim xlsStyleInteger As ExcelStyle = New ExcelStyle()
xlsStyleInteger.setFormat(Format.FORMAT_INTEGER)
xlsCell.setStyle(xlsStyleInteger)
' Apply decimal formatDim xlsStyleDecimals As ExcelStyle = New ExcelStyle()
xlsStyleDecimals.setFormat(Format.FORMAT_FLOAT_2DECIMALS)
xlsCell.setStyle(xlsStyleDecimals)
' Format with red color for negative numbersDim xlsStyleNegative As ExcelStyle = New ExcelStyle()
xlsStyleNegative.setFormat("0.00_);[Red](0.00)")
xlsCell.setStyle(xlsStyleNegative)
C++// Apply integer format
EasyXLS::IExcelStylePtr xlsStyleInteger;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleInteger);
xlsStyleInteger->setFormat(FORMAT_FORMAT_INTEGER);
xlsCell->setStyle(xlsStyleInteger);
// Apply decimal format
EasyXLS::IExcelStylePtr xlsStyleDecimals;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleDecimals);
xlsStyleDecimals->setFormat(FORMAT_FORMAT_FLOAT_2DECIMALS);
xlsCell->setStyle(xlsStyleDecimals);
// Format with red color for negative numbers
EasyXLS::IExcelStylePtr xlsStyleNegative;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleNegative);
xlsStyleNegative->setFormat("0.00_);[Red](0.00)");
xlsCell->setStyle(xlsStyleNegative);
C++.NET// Apply integer format
ExcelStyle ^xlsStyleInteger = gcnew ExcelStyle();
xlsStyleInteger->setFormat(Format::FORMAT_INTEGER);
xlsCell->setStyle(xlsStyleInteger);
// Apply decimal format
ExcelStyle ^xlsStyleDecimals = gcnew ExcelStyle();
xlsStyleDecimals->setFormat(Format::FORMAT_FLOAT_2DECIMALS);
xlsCell->setStyle(xlsStyleDecimals);
// Format with red color for negative numbers
ExcelStyle ^xlsStyleNegative = gcnew ExcelStyle();
xlsStyleNegative->setFormat("0.00_);[Red](0.00)");
xlsCell->setStyle(xlsStyleNegative);
// Apply integer format
ExcelStyle xlsStyleInteger = new ExcelStyle();
xlsStyleInteger.setFormat(Format.FORMAT_INTEGER);
xlsCell.setStyle(xlsStyleInteger);
// Apply decimal format
ExcelStyle xlsStyleDecimals = new ExcelStyle();
xlsStyleDecimals.setFormat(Format.FORMAT_FLOAT_2DECIMALS);
xlsCell.setStyle(xlsStyleDecimals);
// Format with red color for negative numbers
ExcelStyle xlsStyleNegative = new ExcelStyle();
xlsStyleNegative.setFormat("0.00_);[Red](0.00)");
xlsCell.setStyle(xlsStyleNegative);
.NET:// Apply integer format
$xlsStyleInteger = new COM("EasyXLS.ExcelStyle");
$xlsStyleInteger->setFormat($FORMAT_FORMAT_INTEGER);
$xlsCell->setStyle($xlsStyleInteger);
// Apply decimal format
$xlsStyleDecimals = new COM("EasyXLS.ExcelStyle");
$xlsStyleDecimals->setFormat($FORMAT_FORMAT_FLOAT_2DECIMALS);
$xlsCell->setStyle($xlsStyleDecimals);
// Format with red color for negative numbers
$xlsStyleNegative = new COM("EasyXLS.ExcelStyle");
$xlsStyleNegative->setFormat("0.00_);[Red](0.00)");
$xlsCell->setStyle($xlsStyleNegative);
Java:// Apply integer format
$xlsStyleInteger = new java("EasyXLS.ExcelStyle");
$xlsStyleInteger->setFormat($FORMAT_FORMAT_INTEGER);
$xlsCell->setStyle($xlsStyleInteger);
// Apply decimal format
$xlsStyleDecimals = new java("EasyXLS.ExcelStyle");
$xlsStyleDecimals->setFormat($FORMAT_FORMAT_FLOAT_2DECIMALS);
$xlsCell->setStyle($xlsStyleDecimals);
// Format with red color for negative numbers
$xlsStyleNegative = new java("EasyXLS.ExcelStyle");
$xlsStyleNegative->setFormat("0.00_);[Red](0.00)");
$xlsCell->setStyle($xlsStyleNegative);
' Apply integer formatset xlsStyleInteger = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleInteger.setFormat(FORMAT_FORMAT_INTEGER)
xlsCell.setStyle(xlsStyleInteger)
' Apply decimal formatset xlsStyleDecimals = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleDecimals.setFormat(FORMAT_FORMAT_FLOAT_2DECIMALS)
xlsCell.setStyle(xlsStyleDecimals)
' Format with red color for negative numbersset xlsStyleNegative = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleNegative.setFormat("0.00_);[Red](0.00)")
xlsCell.setStyle(xlsStyleNegative)
' Apply integer formatSet xlsStyleInteger = CreateObject("EasyXLS.ExcelStyle")
xlsStyleInteger.setFormat(FORMAT_FORMAT_INTEGER)
xlsCell.setStyle(xlsStyleInteger)
' Apply decimal formatSet xlsStyleDecimals = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDecimals.setFormat(FORMAT_FORMAT_FLOAT_2DECIMALS)
xlsCell.setStyle(xlsStyleDecimals)
' Format with red color for negative numbersSet xlsStyleNegative = CreateObject("EasyXLS.ExcelStyle")
xlsStyleNegative.setFormat("0.00_);[Red](0.00)")
xlsCell.setStyle(xlsStyleNegative)
' Apply integer formatset xlsStyleInteger = CreateObject("EasyXLS.ExcelStyle")
xlsStyleInteger.setFormat(FORMAT_FORMAT_INTEGER)
xlsCell.setStyle(xlsStyleInteger)
' Apply decimal formatset xlsStyleDecimals = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDecimals.setFormat(FORMAT_FORMAT_FLOAT_2DECIMALS)
xlsCell.setStyle(xlsStyleDecimals)
' Format with red color for negative numbersset xlsStyleNegative = CreateObject("EasyXLS.ExcelStyle")
xlsStyleNegative.setFormat("0.00_);[Red](0.00)")
xlsCell.setStyle(xlsStyleNegative)
<!-- Apply integer format --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleInteger"action="CREATE"><cfset xlsStyleInteger.setFormat(Format.FORMAT_INTEGER)><cfset xlsCell.setStyle(xlsStyleInteger)><!-- Apply decimal format --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleDecimals"action="CREATE"><cfset xlsStyleDecimals.setFormat(Format.FORMAT_FLOAT_2DECIMALS)><cfset xlsCell.setStyle(xlsStyleDecimals)><!-- Format with red color for negative numbers --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleNegative"action="CREATE"><cfset xlsStyleNegative.setFormat("0.00_);[Red](0.00)")><cfset xlsCell.setStyle(xlsStyleNegative)>
.NET:# Apply integer format
xlsStyleInteger = ExcelStyle()
xlsStyleInteger.setFormat(Format.FORMAT_INTEGER)
xlsCell.setStyle(xlsStyleInteger)
# Apply decimal format
xlsStyleDecimals = ExcelStyle()
xlsStyleDecimals.setFormat(Format.FORMAT_FLOAT_2DECIMALS)
xlsCell.setStyle(xlsStyleDecimals)
# Format with red color for negative numbers
xlsStyleNegative = ExcelStyle()
xlsStyleNegative.setFormat("0.00_);[Red](0.00)")
xlsCell.setStyle(xlsStyleNegative)
Java:# Apply integer format
xlsStyleInteger = gateway.jvm.ExcelStyle()
xlsStyleInteger.setFormat(gateway.jvm.Format.FORMAT_INTEGER)
xlsCell.setStyle(xlsStyleInteger)
# Apply decimal format
xlsStyleDecimals = gateway.jvm.ExcelStyle()
xlsStyleDecimals.setFormat(gateway.jvm.Format.FORMAT_FLOAT_2DECIMALS)
xlsCell.setStyle(xlsStyleDecimals)
# Format with red color for negative numbers
xlsStyleNegative = gateway.jvm.ExcelStyle()
xlsStyleNegative.setFormat("0.00_);[Red](0.00)")
xlsCell.setStyle(xlsStyleNegative)
Currency format
The currency format includes 1000 separator, decimal separator, decimal places, currency symbol and the aspect for negative numbers. The 1000 separator must be always set as "," and decimal separator as ".". The regional settings from the machine are used when the Excel file is opened, and the separators set in Control Panel define the displayed separators on screen.
The below source code sample shows how to set the default currency format and a currency format for negative numbers.
// Apply currency format
ExcelStyle xlsStyleCurrency = new ExcelStyle();
xlsStyleCurrency.setFormat(Format.FORMAT_CURRENCY);
xlsCell.setStyle(xlsStyleCurrency);
// Format with red color for negative numbers
ExcelStyle xlsStyleNegative = new ExcelStyle();
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)");
xlsCell.setStyle(xlsStyleNegative);
' Apply currency formatDim xlsStyleCurrency As ExcelStyle = New ExcelStyle()
xlsStyleCurrency.setFormat(Format.FORMAT_CURRENCY)
xlsCell.setStyle(xlsStyleCurrency)
' Format with red color for negative numbersDim xlsStyleNegative As ExcelStyle = New ExcelStyle()
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)")
xlsCell.setStyle(xlsStyleNegative)
C++// Apply currency format
EasyXLS::IExcelStylePtr xlsStyleCurrency;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleCurrency);
xlsStyleCurrency->setFormat(FORMAT_FORMAT_CURRENCY);
xlsCell->setStyle(xlsStyleCurrency);
// Format with red color for negative numbers
EasyXLS::IExcelStylePtr xlsStyleNegative;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleNegative);
xlsStyleNegative->setFormat("$#,##0.00_);[Red]($#,##0.00)");
xlsCell->setStyle(xlsStyleNegative);
C++.NET// Apply currency format
ExcelStyle ^xlsStyleCurrency = gcnew ExcelStyle();
xlsStyleCurrency->setFormat(Format::FORMAT_CURRENCY);
xlsCell->setStyle(xlsStyleCurrency);
// Format with red color for negative numbers
ExcelStyle ^xlsStyleNegative = gcnew ExcelStyle();
xlsStyleNegative->setFormat("$#,##0.00_);[Red]($#,##0.00)");
xlsCell->setStyle(xlsStyleNegative);
// Apply currency format
ExcelStyle xlsStyleCurrency = new ExcelStyle();
xlsStyleCurrency.setFormat(Format.FORMAT_CURRENCY);
xlsCell.setStyle(xlsStyleCurrency);
// Format with red color for negative numbers
ExcelStyle xlsStyleNegative = new ExcelStyle();
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)");
xlsCell.setStyle(xlsStyleNegative);
.NET:// Apply currency format
$xlsStyleCurrency = new COM("EasyXLS.ExcelStyle");
$xlsStyleCurrency->setFormat($FORMAT_FORMAT_CURRENCY);
$xlsCell->setStyle($xlsStyleCurrency);
// Format with red color for negative numbers
$xlsStyleNegative = new COM("EasyXLS.ExcelStyle");
$xlsStyleNegative->setFormat("$#,##0.00_);[Red]($#,##0.00)");
$xlsCell->setStyle($xlsStyleNegative);
Java:// Apply currency format
$xlsStyleCurrency = new java("EasyXLS.ExcelStyle");
$xlsStyleCurrency->setFormat($FORMAT_FORMAT_CURRENCY);
$xlsCell->setStyle($xlsStyleCurrency);
// Format with red color for negative numbers
$xlsStyleNegative = new java("EasyXLS.ExcelStyle");
$xlsStyleNegative->setFormat("$#,##0.00_);[Red]($#,##0.00)");
$xlsCell->setStyle($xlsStyleNegative);
' Apply currency formatset xlsStyleCurrency = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleCurrency.setFormat(FORMAT_FORMAT_CURRENCY)
xlsCell.setStyle(xlsStyleCurrency)
' Format with red color for negative numbersset xlsStyleNegative = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)")
xlsCell.setStyle(xlsStyleNegative)
' Apply currency formatSet xlsStyleCurrency = CreateObject("EasyXLS.ExcelStyle")
xlsStyleCurrency.setFormat(FORMAT_FORMAT_CURRENCY)
xlsCell.setStyle(xlsStyleCurrency)
' Format with red color for negative numbersSet xlsStyleNegative = CreateObject("EasyXLS.ExcelStyle")
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)")
xlsCell.setStyle(xlsStyleNegative)
' Apply currency formatset xlsStyleCurrency = CreateObject("EasyXLS.ExcelStyle")
xlsStyleCurrency.setFormat(FORMAT_FORMAT_CURRENCY)
xlsCell.setStyle(xlsStyleCurrency)
' Format with red color for negative numbersset xlsStyleNegative = CreateObject("EasyXLS.ExcelStyle")
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)")
xlsCell.setStyle(xlsStyleNegative)
<!-- Apply currency format --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleCurrency"action="CREATE"><cfset xlsStyleCurrency.setFormat(Format.FORMAT_CURRENCY)><cfset xlsCell.setStyle(xlsStyleCurrency)><!-- Format with red color for negative numbers --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleNegative"action="CREATE"><cfset xlsStyleNegative.setFormat("$##,####0.00_);[Red]($##,####0.00)")><cfset xlsCell.setStyle(xlsStyleNegative)>
.NET:# Apply currency format
xlsStyleCurrency = ExcelStyle()
xlsStyleCurrency.setFormat(Format.FORMAT_CURRENCY)
xlsCell.setStyle(xlsStyleCurrency)
# Format with red color for negative numbers
xlsStyleNegative = ExcelStyle()
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)")
xlsCell.setStyle(xlsStyleNegative)
Java:# Apply currency format
xlsStyleCurrency = gateway.jvm.ExcelStyle()
xlsStyleCurrency.setFormat(gateway.jvm.Format.FORMAT_CURRENCY)
xlsCell.setStyle(xlsStyleCurrency)
# Format with red color for negative numbers
xlsStyleNegative = gateway.jvm.ExcelStyle()
xlsStyleNegative.setFormat("$#,##0.00_);[Red]($#,##0.00)")
xlsCell.setStyle(xlsStyleNegative)
Accounting format
The accounting format includes 1000 separator, decimal separator, decimal places, currency symbol and the aspect for negative numbers. The 1000 separator must be always set as "," and decimal separator as ".". The regional settings from the machine are used when the Excel file is opened, and the separators set in Control Panel define the displayed separators on screen.
The below source code sample shows how to set the default accounting format.
// Apply date format
ExcelStyle xlsStyleDate = new ExcelStyle();
xlsStyleDate.setFormat(Format.FORMAT_DATE);
xlsCell1.setStyle(xlsStyleDate);
// Apply date format with regional settings
ExcelStyle xlsStyleDateRegional = new ExcelStyle();
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_REGIONAL_SETTINGS);
xlsCell2.setStyle(xlsStyleDateRegional);
' Apply date formatDim xlsStyleDate As ExcelStyle = New ExcelStyle()
xlsStyleDate.setFormat(Format.FORMAT_DATE)
xlsCell1.setStyle(xlsStyleDate)
' Apply date format with regional settingsDim xlsStyleDateRegional As ExcelStyle = New ExcelStyle()
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
C++// Apply date format
EasyXLS::IExcelStylePtr xlsStyleDate;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleDate);
xlsStyleDate->setFormat(FORMAT_FORMAT_DATE);
xlsCell1->setStyle(xlsStyleDate);
// Apply date format with regional settings
EasyXLS::IExcelStylePtr xlsStyleDateRegional;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleDateRegional);
xlsStyleDateRegional->setFormat(FORMAT_FORMAT_DATE_REGIONAL_SETTINGS);
xlsCell2->setStyle(xlsStyleDateRegional);
C++.NET// Apply date format
ExcelStyle ^xlsStyleDate = gcnew ExcelStyle();
xlsStyleDate->setFormat(Format::FORMAT_DATE);
xlsCell1->setStyle(xlsStyleDate);
// Apply date format with regional settings
ExcelStyle ^xlsStyleDateRegional = gcnew ExcelStyle();
xlsStyleDateRegional->setFormat(Format::FORMAT_DATE_REGIONAL_SETTINGS);
xlsCell2->setStyle(xlsStyleDateRegional);
// Apply date format
ExcelStyle xlsStyleDate = new ExcelStyle();
xlsStyleDate.setFormat(Format.FORMAT_DATE);
xlsCell1.setStyle(xlsStyleDate);
// Apply date format with regional settings
ExcelStyle xlsStyleDateRegional = new ExcelStyle();
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_REGIONAL_SETTINGS);
xlsCell2.setStyle(xlsStyleDateRegional);
.NET:// Apply date format
$xlsStyleDate = new COM("EasyXLS.ExcelStyle");
$xlsStyleDate->setFormat($FORMAT_FORMAT_DATE);
$xlsCell1->setStyle($xlsStyleDate);
// Apply date format with regional settings
$xlsStyleDateRegional = new COM("EasyXLS.ExcelStyle");
$xlsStyleDateRegional->setFormat($FORMAT_FORMAT_DATE_REGIONAL_SETTINGS);
$xlsCell2->setStyle($xlsStyleDateRegional);
Java:// Apply date format
$xlsStyleDate = new java("EasyXLS.ExcelStyle");
$xlsStyleDate->setFormat($FORMAT_FORMAT_DATE);
$xlsCell1->setStyle($xlsStyleDate);
// Apply date format with regional settings
$xlsStyleDateRegional = new java("EasyXLS.ExcelStyle");
$xlsStyleDateRegional->setFormat($FORMAT_FORMAT_DATE_REGIONAL_SETTINGS);
$xlsCell2->setStyle($xlsStyleDateRegional);
' Apply date formatset xlsStyleDate = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleDate.setFormat(FORMAT_FORMAT_DATE)
xlsCell1.setStyle(xlsStyleDate)
' Apply date format with regional settingsset xlsStyleDateRegional = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleDateRegional.setFormat(FORMAT_FORMAT_DATE_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
' Apply date formatSet xlsStyleDate = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDate.setFormat(FORMAT_FORMAT_DATE)
xlsCell1.setStyle(xlsStyleDate)
' Apply date format with regional settingsSet xlsStyleDateRegional = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDateRegional.setFormat(FORMAT_FORMAT_DATE_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
' Apply date formatset xlsStyleDate = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDate.setFormat(FORMAT_FORMAT_DATE)
xlsCell1.setStyle(xlsStyleDate)
' Apply date format with regional settingsset xlsStyleDateRegional = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDateRegional.setFormat(FORMAT_FORMAT_DATE_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
<!-- Apply date format --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleDate"action="CREATE"><cfset xlsStyleDate.setFormat(Format.FORMAT_DATE)><cfset xlsCell1.setStyle(xlsStyleDate)><!-- Apply date format with regional settings --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleDateRegional"action="CREATE"><cfset xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_REGIONAL_SETTINGS)><cfset xlsCell2.setStyle(xlsStyleDateRegional)>
.NET:# Apply date format
xlsStyleDate = ExcelStyle()
xlsStyleDate.setFormat(Format.FORMAT_DATE)
xlsCell1.setStyle(xlsStyleDate)
# Apply date format with regional settings
xlsStyleDateRegional = ExcelStyle()
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
Java:# Apply date format
xlsStyleDate = gateway.jvm.ExcelStyle()
xlsStyleDate.setFormat(gateway.jvm.Format.FORMAT_DATE)
xlsCell1.setStyle(xlsStyleDate)
# Apply date format with regional settings
xlsStyleDateRegional = gateway.jvm.ExcelStyle()
xlsStyleDateRegional.setFormat(gateway.jvm.Format.FORMAT_DATE_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
Time format
The time format is used to set how time fraction is displayed on screen. Part of time formats depend by the regional settings from the machine, others do not.
For better performances, a date value must be entered as "MM/dd/yyyy HH:mm:ss" and the time format applied later to the cell.
The below source code sample shows how to set the custom time format and date time with regional settings.
// Apply time format
ExcelStyle xlsStyleTime = new ExcelStyle();
xlsStyleTime .setFormat("HH:mm:ss");
xlsCell1.setStyle(xlsStyleTime);
// Apply date time format with regional settings
ExcelStyle xlsStyleDateRegional = new ExcelStyle();
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS);
xlsCell2.setStyle(xlsStyleDateRegional);
' Apply time formatDim xlsStyleTime As ExcelStyle = New ExcelStyle()
xlsStyleTime.setFormat("HH:mm:ss")
xlsCell1.setStyle(xlsStyleTime)
' Apply date time format with regional settingsDim xlsStyleDateRegional As ExcelStyle = New ExcelStyle()
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
C++// Apply time format
EasyXLS::IExcelStylePtr xlsStyleTime;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleTime);
xlsStyleTime->setFormat("HH:mm:ss");
xlsCell1->setStyle(xlsStyleTime);
// Apply date time format with regional settings
EasyXLS::IExcelStylePtr xlsStyleDateRegional;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**)&xlsStyleDateRegional);
xlsStyleDateRegional->setFormat(FORMAT_FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS);
xlsCell2->setStyle(xlsStyleDateRegional);
C++.NET// Apply time format
ExcelStyle ^xlsStyleTime = gcnew ExcelStyle();
xlsStyleTime->setFormat("HH:mm:ss");
xlsCell1->setStyle(xlsStyleTime);
// Apply date time format with regional settings
ExcelStyle ^xlsStyleDateRegional = gcnew ExcelStyle();
xlsStyleDateRegional->setFormat(Format::FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS);
xlsCell2->setStyle(xlsStyleDateRegional);
// Apply time format
ExcelStyle xlsStyleTime = new ExcelStyle();
xlsStyleTime .setFormat("HH:mm:ss");
xlsCell1.setStyle(xlsStyleTime);
// Apply date time format with regional settings
ExcelStyle xlsStyleDateRegional = new ExcelStyle();
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS);
xlsCell2.setStyle(xlsStyleDateRegional);
.NET:// Apply time format
$xlsStyleTime = new COM("EasyXLS.ExcelStyle");
$xlsStyleTime->setFormat("HH:mm:ss");
$xlsCell1->setStyle($xlsStyleTime);
// Apply date time format with regional settings
$xlsStyleDateRegional = new COM("EasyXLS.ExcelStyle");
$xlsStyleDateRegional->setFormat($FORMAT_FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS);
$xlsCell2->setStyle($xlsStyleDateRegional);
Java:// Apply time format
$xlsStyleTime = new java("EasyXLS.ExcelStyle");
$xlsStyleTime->setFormat("HH:mm:ss");
$xlsCell1->setStyle($xlsStyleTime);
// Apply date time format with regional settings
$xlsStyleDateRegional = new java("EasyXLS.ExcelStyle");
$xlsStyleDateRegional->setFormat($FORMAT_FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS);
$xlsCell2->setStyle($xlsStyleDateRegional);
' Apply time formatset xlsStyleTime = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleTime.setFormat("HH:mm:ss")
xlsCell1.setStyle(xlsStyleTime)
' Apply date time format with regional settingsset xlsStyleDateRegional = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleDateRegional.setFormat(FORMAT_FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
' Apply time formatSet xlsStyleTime = CreateObject("EasyXLS.ExcelStyle")
xlsStyleTime.setFormat("HH:mm:ss")
xlsCell1.setStyle(xlsStyleTime)
' Apply date time format with regional settingsSet xlsStyleDateRegional = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDateRegional.setFormat(FORMAT_FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
' Apply time formatset xlsStyleTime = CreateObject("EasyXLS.ExcelStyle")
xlsStyleTime.setFormat("HH:mm:ss")
xlsCell1.setStyle(xlsStyleTime)
' Apply date time format with regional settingsset xlsStyleDateRegional = CreateObject("EasyXLS.ExcelStyle")
xlsStyleDateRegional.setFormat(FORMAT_FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
<!-- Apply time format --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleTime"action="CREATE"><cfset xlsStyleTime.setFormat("HH:mm:ss")><cfset xlsCell1.setStyle(xlsStyleTime)><!-- Apply date time format with regional settings --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleDateRegional"action="CREATE"><cfset xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS)><cfset xlsCell2.setStyle(xlsStyleDateRegional)>
.NET:# Apply time format
xlsStyleTime = ExcelStyle()
xlsStyleTime.setFormat("HH:mm:ss")
xlsCell1.setStyle(xlsStyleTime)
# Apply date time format with regional settings
xlsStyleDateRegional = ExcelStyle()
xlsStyleDateRegional.setFormat(Format.FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
Java:# Apply time format
xlsStyleTime = gateway.jvm.ExcelStyle()
xlsStyleTime.setFormat("HH:mm:ss")
xlsCell1.setStyle(xlsStyleTime)
# Apply date time format with regional settings
xlsStyleDateRegional = gateway.jvm.ExcelStyle()
xlsStyleDateRegional.setFormat(
gateway.jvm.Format.FORMAT_DATE_AND_TIME_REGIONAL_SETTINGS)
xlsCell2.setStyle(xlsStyleDateRegional)
Percent format
The percent format is used to display numbers as percentages.
The below source code sample shows how to set the percentage format.
// Apply percentage format
ExcelStyle xlsStylePercentage = new ExcelStyle();
xlsStylePercentage.setFormat(Format.FORMAT_FLOAT_2DECIMALS_PERCENT);
xlsCell.setStyle(xlsStylePercentage);
.NET:// Apply percentage format
$xlsStylePercentage = new COM("EasyXLS.ExcelStyle");
$xlsStylePercentage->setFormat($FORMAT_FORMAT_FLOAT_2DECIMALS_PERCENT);
$xlsCell->setStyle($xlsStylePercentage);
Java:// Apply percentage format
$xlsStylePercentage = new java("EasyXLS.ExcelStyle");
$xlsStylePercentage->setFormat($FORMAT_FORMAT_FLOAT_2DECIMALS_PERCENT);
$xlsCell->setStyle($xlsStylePercentage);