0

Using Delphi 2007 & trying to read a txt file with greek characters & opening with Excel, I am not getting greek characters but symbols...Any help?

The text file is created with this code

CSVSTRList.SaveToFile('c:\test\xxx2.txt');

where CSVSTRList is a TStringList.

LU RD
  • 34,438
  • 5
  • 88
  • 296
VaVel
  • 69
  • 3
  • 13

1 Answers1

3

Looking at your code in your previous question it seems you are taking a stock TStringList and calling SaveToFile. That encodes the text as ANSI. Your Greek characters cannot be encoded as ANSI.

You want to export text using a Unicode encoding. For instance, in a modern Delphi you would use:

StringList.SaveToFile(FileName, Encoding.Unicode);

for UTF-16, or

StringList.SaveToFile(FileName, Encoding.UTF8);

for UTF-8.

I would expect that Excel will understand either of these encodings.

Since you are using a non-Unicode Delphi, things are somewhat more difficult. You'll need to change all you code, every single piece of string handling, to be Unicode aware. So you cannot use the stock string list any more, for example, because it contains 8 bit ANSI strings. The simplest way to do this with legacy Delphi is with the TNT Unicode library.

Or you could take the step of moving to a Unicode Delphi. If you care about international text it is the most sensible option.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    Delphi 2007 didn't have parameter for encoding in the [`SaveToFile`](http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate3/EN/html/delphivclwin32/Classes_TStrings_SaveToFile.html) method yet. – TLama Feb 02 '14 at 12:18
  • 1
    @TLama Thanks. Had not spotted that. – David Heffernan Feb 02 '14 at 12:21