Lazarus

Programming => Packages and Libraries => FPSpreadsheet => Topic started by: Jvan on May 07, 2021, 12:56:52 am

Title: How to set a number format for WriteNumber(...) and WriteFormula(...)?
Post by: Jvan on May 07, 2021, 12:56:52 am
Please, how to do it?

I'm using formulas to sum these numbers too.


Thanks.
Title: Re: How to set a number format for WriteNumber(...) and WriteFormula(...)?
Post by: wp 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.
Title: Re: How to set a number format for WriteNumber(...) and WriteFormula(...)?
Post by: Jvan on May 07, 2021, 09:51:08 pm
Thanks.
TinyPortal © 2005-2018