ExcelWriter allows you to create custom formats as required. Two examples of this follow below. The first example
demonstrates the creation of a custom "TimeStamp" format. The second example demonstrates the creation of a custom "Eurodollar" format.
Example #1: "TimeStamp" date and time format
<%
Dim TimeStampStyle, RowCount, X
'--- Create custom "TimeStampStyle" for formatting all rows in a column 1
'--- to display the full date and time (time stamp)
set TimeStampStyle = XLW.CreateStyle
TimeStampStyle.Number = "mm/dd/yyyy hh:mm:ss AM/PM"
RowCount = 40
X = 1
'--- Use looping to apply "TimeStampStyle" to all rows in column 1
Do While X <= RowCount
ws.Cells(X, 1).Style = TimeStampStyle
'-- Iterate RowCount
X = X + 1
loop
%>
Please note: It is very important that the slashes in the custom format are forward
slashes "/". The formatting will not work correctly if back slashes "\" are employed.
Example #2: "Eurodollar" currency format
<%
Dim EurodollarStyle, RowCount, X
'--- Create custom "EurodollarStyle" for formatting all rows in a column 2
'--- This custom style will prefix the "€" sign and show all values with two decimal places
'--- and losses will appear in parenthesis
Set EurodollarStyle = XLW.CreateStyle
EurodollarStyle.Number = "€ #,##0.00;(€ #,##0.00)"
'--- Use looping to apply "EurodollarStyle" to all rows in column 2
Do While X <= RowCount
ws.Cells(X, 2).Style = EurodollarStyle
'-- Iterate RowCount
X = X + 1
loop
%>
This custom "EurodollarStyle" expands upon the pre-defined currency format (number = 7) by replacing
the U.S.A. "$" sign with the Eurodollar "€" symbol while retaining the two decimal places and showing losses
in parenthesis.
|