Reading txt file & opening with excel

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.

Answers


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.


Need Your Help

C++, GTK+, and String types

c++ string gtk

Excuse my ignorance here but I know neither C++ nor GTK+.

Have mouse over rather than text symbol

jquery html css

I have a code here that inputs the text you click on into a textbox below.