Autor Beitrag
ruewue
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Do 28.07.11 08:54 
Hallo Zusammen,

ich habe ein Probelm beim Erstellen eine EXCEL Datei. Unter Windows XP mit Delphi 7 hat alles super funktioniert. Nun habe ich das Programm nach einer Änderung unter Win7 mit Embarcadero Delphi XE kompiliert und das EXCEL sieht bescheiden aus.

Vorher:
Dies ist ein ganz normaler Text

Jetzt:
D i e s _ i s t _ e i n _ g a n z _ n o r m a l e r _ T e x t (_ steht für 3 Leerstellen)



Ich habe schon einiges versucht. Doch ich kriege diese überflüssinge "nul" Werte nicht raus. Auch durch googeln bin ich nicht schlauer geworden.

hier der Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
//***************************************************************************************************
// Text in eine Excel Celle schreiben
//***************************************************************************************************
procedure XlsWriteCellLabel(XlsStream: TStream; const ACol, ARow: Word; const AValue: UnicodeString);
var
  L : Word;

const
{$J+}
  CXlsLabel : array [0 .. 5of Word = ($20400000);
{$J-}
begin
  L := Length(AValue) * SizeOf(WideChar);

  CXlsLabel[1] := 8 + L;
  CXlsLabel[2] := ARow;
  CXlsLabel[3] := ACol;
  CXlsLabel[5] := L;

  XlsStream.WriteBuffer(CXlsLabel, SizeOf(CXlsLabel));
  XlsStream.WriteBuffer(Pointer(AValue)^, L);
end;

Bin für jeden Tip dankbar!

Rüdiger

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 28.07.11 11:00 
user profile iconruewue hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
  XlsStream.WriteBuffer(Pointer(AValue)^, L);
end;
Du schreibst hier explizit einen UnicodeString. Und der besteht eben aus zwei Byte pro Zeichen. Wenn du AnsiStrings willst, musst du auch einen nehmen...
ruewue Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Do 28.07.11 13:56 
Hallo Zusammen

hier die Lösung, welche bei mir funktioniert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure XlsWriteCellLabel(XlsStream: TStream; const ACol, ARow: Word; const AValue: String);
var
  L : Word;

const
{$J+}
  CXlsLabel : array [0 .. 5of Word = ($20400000);
{$J-}
begin
  L := Length(AValue);

  CXlsLabel[1] := 8 + L;
  CXlsLabel[2] := ARow;
  CXlsLabel[3] := ACol;
  CXlsLabel[5] := L;

  XlsStream.WriteBuffer(CXlsLabel, SizeOf(CXlsLabel));
  XlsStream.WriteBuffer(Pointer(Utf8String(AValue))^, L);
end;


Danke für die Hilfe!