Recent

Author Topic: numeric format number in cell  (Read 7519 times)

pomalo

  • New Member
  • *
  • Posts: 11
numeric format number in cell
« on: August 20, 2013, 09:58:57 am »
hello

In my application,  data are extracted from a mysql database and write it to an ods worsheet
some cell contain currency number and are read from database with
Code: [Select]
MyWorksheet.WriteNumber( row,2, FieldByName('price').AsCurrency);

When reading the spreadsheet with Openoffice the price become for exemple '2' in place of '2.00' or "2.5" in place of '2.50'.

Is there a way to format the numeric cell containt


thank for your help
Claude

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: numeric format number in cell
« Reply #1 on: August 20, 2013, 10:01:14 am »
Fields->Properties(Object inspector)->DisplayFormat

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: numeric format number in cell
« Reply #2 on: August 20, 2013, 10:03:25 am »
Example
Format : #0.00 -> 123=> 123.00,  12.1 => 12.10 etc.


exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: numeric format number in cell
« Reply #4 on: August 20, 2013, 10:24:07 am »
-----------http://wiki.freepascal.org/FPSpreadsheet#Using_formatting_options-------
 Using formatting options

The formatting is set independently from the text, as in the example below:

  // Write a bold text
  MyWorksheet.WriteUTF8Text(0, 0, 'First');
  MyWorksheet.WriteUsedFormatting(0, 0, [uffBold]);
----------http://wiki.freepascal.org/FPSpreadsheet#Using_formatting_options-------
so, you can use : MyWorksheet.WriteUTF8Text(0, 0, Format('2.f', [your_numeric]))
http://wiki.freepascal.org/FPSpreadsheet#Using_formatting_options
« Last Edit: August 20, 2013, 10:33:09 am by exdatis »

pomalo

  • New Member
  • *
  • Posts: 11
Re: numeric format number in cell
« Reply #5 on: August 20, 2013, 12:59:42 pm »
so, you can use : MyWorksheet.WriteUTF8Text(0, 0, Format('2.f', [your_numeric]))
http://wiki.freepascal.org/FPSpreadsheet#Using_formatting_options

thank this can work but content is left justified (because is text) and i have note see formating setting to right justify in fpspreadsheet.pas 

try to set  cell to "cctNumber" content type  after value attribution with
Code: [Select]
myCell :=  MyWorksheet.GetCell(row,2);
myCell^.ContentType := cctNumber;

but cell content became "0"

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: numeric format number in cell
« Reply #6 on: August 20, 2013, 02:18:04 pm »
I have no experience, perhaps someone else can help.
Regards

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: numeric format number in cell
« Reply #7 on: August 21, 2013, 06:27:05 am »
Which format are you writing to?

pomalo

  • New Member
  • *
  • Posts: 11
Re: numeric format number in cell
« Reply #8 on: August 21, 2013, 09:26:40 am »
i have try
with value = 10.50
Code: [Select]
format('%10.2f')result is 10.50 but left align
Code: [Select]
format('%10.2m')result is 10.50 € but left align

Code: [Select]
formatCurr('#######0.00')result is 10.50 but left align

Code: [Select]
formatCurr('0000000.00')
result is 0000010.50 and right align.

i'm think that fpspreadsheet trim the result before wiriting it to cell (bug?)





felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: numeric format number in cell
« Reply #9 on: August 21, 2013, 02:23:47 pm »
Not this format ... I meant the file format: if you are writing a Excel2, Excel5, Excel8, or OpenDocument or OOXML document ...

pomalo

  • New Member
  • *
  • Posts: 11
Re: numeric format number in cell
« Reply #10 on: August 21, 2013, 06:10:15 pm »
i have the same result with
sfOpenDocument and sfExcel5

thank
claude

 

TinyPortal © 2005-2018