Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi OLE-Excel Problem - Formatierung in Excel (https://www.delphipraxis.net/11758-ole-excel-problem-formatierung-excel.html)

Gouston 13. Nov 2003 11:58


OLE-Excel Problem - Formatierung in Excel
 
Hallo ,

ich habe folgendes:

Delphi-Quellcode:
//...
 
  Sheet.Cells[1, 1] := Query1.FieldByName('feld1').asFloat;

//...
Wenn in feld1 der Wert 2123,40 steht, erhalte ich im Sheet 2123,4
Ich hätte aber gerne 2.123,40 drin stehen. Natürlich nicht im Textformat,
sondern im Zahlenformat. Ich muss in Excel damit rechnen können.

Kann jemand einen Tipp geben ?

Gouston

horst 13. Nov 2003 12:26

Re: OLE-Excel Problem - Formatierung in Excel
 
vielleicht so
Delphi-Quellcode:
Sheet.Cells[1, 1] := Query1.FieldByName('feld1').AsInteger;

Gouston 13. Nov 2003 13:22

Re: OLE-Excel Problem - Formatierung in Excel
 
nee...geht nicht.
Das Feld in der Datenbank ist Number mit Nachkommastellen...also Float für Delphi.

PeterRettig 13. Nov 2003 14:37

Re: OLE-Excel Problem - Formatierung in Excel
 
Hallo Gouston,

du musst vorher die Formatierung der Zelle in Excel ändern.
Also zuerst die gewünschte Zeile selektieren:

z.B.: Range("A3").Select

Und danach die Formatierung anpassen:
Selection.NumberFormat = "0.00"

Ciao Peter

Gouston 14. Nov 2003 08:31

Re: OLE-Excel Problem - Formatierung in Excel
 
Hallo Peter,

danke für den Tip !

So geht's :

Delphi-Quellcode:
var
 vBetrag : extended;
begin
//  ...
 DecimalSeparator := '.';
 ThousandSeparator := ',';

 vBetrag := Query1.GetField('feld1');
 Sheet.Cells[1,1].select;
 Excel.Selection.NumberFormat := '#.##0,00';
 Sheet.Cells[1,1].FormulaR1C1 := vPBetrag;
//...
Gouston


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz