Hi,
I'm testing XLSReadWriteII4 trial version. (First time to use any XLSReadWrite version.)
While this software may be intuitive and obvious to many, it's not to me!
After searching through the help file and this bulletin board, I can't find any information about formatting a cell to 'currency'.
I'm using Delphi 2010 to build a spreadsheet.
Most of this program works, but I can't figure out how to format a particular cell as "currency" (with it's associated parameters).
Here's a brief sample of what I'm doing:
with XLRW.Sheet[0] do
begin
Range.ItemsRef['A2:J6'].FontStyle := [xfsBold];
Columns.AddIfNone(8,1); //Column 'I'
Columns[8].PixelWidth := 96;
Range.ItemsRef['A2:J6].VertAlignment := cvaCenter;
Range.ItemsRef['C5:I6].HorizAlignment := chaCenter;
AsFormula[8,5] := 'SUM(H6:H7)';
//
// This is where I would like to format Cell[8,5] as currency with 2 decimal places and a symbol, e.g. $87.23
end;
If it is possible to do this, could someone provide a line of sample code to point me in the right direction? (And what, if anything, I need to include in the 'uses' clause.)
Many thanks in advance.
(PS - If there are easier ways to write the code above, any helpful pointers would be greatly appreciated!)
Currency format
-
- Posts: 13
- Joined: Tue Feb 13, 2007 8:47 am
- Location: West Sussex England
Re: Currency format
The way I usually sort this sort of thing out is to go into Excel and record a macro doing what I want, then translate that into xlsReadWrite.
For example, I just told Excel to use currency format on a cell and accepted the defaults. The resulting macro was:
Selection.NumberFormat = "$#,##0.00"
Interestingly, being in the UK, my CurrencySymbol is the UK-pound sign, but it still shows the generic '$' in the format statement.
in your example, I'd use the following code:
Cell[8,5].NumberFormat = '$#,##0.00'; // Note change of quotes
hope that helps,
For example, I just told Excel to use currency format on a cell and accepted the defaults. The resulting macro was:
Selection.NumberFormat = "$#,##0.00"
Interestingly, being in the UK, my CurrencySymbol is the UK-pound sign, but it still shows the generic '$' in the format statement.
in your example, I'd use the following code:
Cell[8,5].NumberFormat = '$#,##0.00'; // Note change of quotes
hope that helps,
Joe Griffin
GerbilSoft Associates Limited
GerbilSoft Associates Limited