### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: How to set a number format for WriteNumber(...) and WriteFormula(...)?  (Read 1026 times)

#### Jvan

• Full Member
• Posts: 181
##### How to set a number format for WriteNumber(...) and WriteFormula(...)?
« on: May 07, 2021, 12:56:52 am »
Please, how to do it?

I'm using formulas to sum these numbers too.

Thanks.
« Last Edit: May 07, 2021, 12:59:59 am by Jvan »

#### wp

• Hero Member
• Posts: 8385
##### Re: How to set a number format for WriteNumber(...) and WriteFormula(...)?
« Reply #1 on: May 07, 2021, 10:40:25 am »
Code: Pascal  [Select][+][-]
1. program Project1;
2.
3. uses
4.   fpspreadsheet, fpstypes, fpsutils, fpsopendocument;
5. var
6.   wb: TsWorkbook;
7.   sh: TsWorksheet;
8. begin
9.   wb := TsWorkbook.Create;
10.   try
11.     wb.Options := [boAutoCalc];
12.     sh := wb.AddWorksheet('Test');
13.     sh.WriteNumber(0, 0, 2.345678, nfFixed, 3);      // cell A1: 3 decimals
14.     sh.WriteNumber(1, 0, 5349.342863, nfFixedTh, 3); // cell A2: 3 decimals with thousand separator
15.     sh.WriteNumber(2, 0, -2.345678, nfCustom, '0.000;(0.000)');  // cell A3: negative value in parenthesis
16.     sh.Writeformula(3, 0, 'sum(A1:A3)');
17.     sh.WriteNumberFormat(3, 0, nfFixedTh, 3);        // Format for formula cell: 3 decimals with th.sep.
18.     wb.WriteToFile('test.ods', true);
19.   finally
20.     wb.Free;
21.   end;
22. end.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

#### Jvan

• Full Member
• Posts: 181
##### Re: How to set a number format for WriteNumber(...) and WriteFormula(...)?
« Reply #2 on: May 07, 2021, 09:51:08 pm »
Thanks.