Page 1 of 1

Unicode character issue

Posted: Wed Apr 08, 2015 10:15 am
by CareAll
Hello Lars,

I'd like to put a string with some accented characters into a cell. The following line of code

Code: Select all

XLS[0].AsString[0, 0] := 'Kôvàgò Kàlmàn';
gives a wrong result in the Excel file:

Code: Select all

Kôvŕgň Kŕlmŕn
If I append some Japanese characters to the string, like

Code: Select all

XLS[0].AsString[0, 1] := '陰茎 Kôvàgò Kàlmàn';
the result is okay:

Code: Select all

陰茎 Kôvàgò Kàlmàn
Please take a look at this issue.
Sample code sent via e-mail.

Re: Unicode character issue

Posted: Mon Apr 13, 2015 2:39 pm
by larsa
Hello

I can't reproduce this. This shall not be a problem as all strings are unicode. The only way I can think of that this may happen is if you uses a non unicode delphi (before D2009), and you windows is set to a different codepage than the text you writes.

Re: Unicode character issue

Posted: Tue Apr 14, 2015 2:38 pm
by CareAll
Hello Lars,

I'm using Delphi XE7, so it is not likely that this is the cause of the error. Could you please write down what is the output of the sample previously sent to you?

Re: Unicode character issue

Posted: Thu Apr 16, 2015 6:40 am
by larsa
Hello

The output is: "Kôvàgò Kàlmàn"

Re: Unicode character issue

Posted: Fri Apr 17, 2015 1:13 pm
by CareAll
Hello Lars,

I managed to find out how to reproduce the error. With Swedish regional settings the output of the above program is

Code: Select all

Kôvàgò Kàlmàn
陰茎 Kôvàgò Kàlmàn
If you change your Windows location to Hungary and the System Locale to Hungarian (Hungary) the output is

Code: Select all

Kôvŕgň Kŕlmŕn
陰茎 Kôvàgò Kàlmàn
Please try this out.

Re: Unicode character issue

Posted: Mon Apr 20, 2015 1:29 pm
by larsa
Hello

I could reproduce the problem now. In the next update (will post it tomorrow), there is an option XLS.CompressStrings. Set this to False to solve this problem.

Re: Unicode character issue

Posted: Mon Apr 20, 2015 1:34 pm
by CareAll
I will try it, thank you.

Re: Unicode character issue

Posted: Fri Apr 24, 2015 10:16 am
by CareAll
Hello Lars,

I tried out your solution with version 5.20.48, but unfortunately it doesn't work. As far as I can see, the value of CompressStrings doesn't affect the content of the output file. I unpacked the two xlsx files (one with CompressStrings = True and one with False) and compared the files in them, but I found no difference in their contents, except for the time of creation and modification in docProps\core.xml.

The code is:

Code: Select all

procedure TForm1.btn1Click(Sender: TObject);
var
  XLS: TXLSReadWriteII5;
begin
  XLS := TXLSReadWriteII5.Create(nil);
  try
    XLS[0].AsString[0, 0] := 'Kôvàgò Kàlmàn';
    XLS[0].AsString[0, 1] := '陰茎 Kôvàgò Kàlmàn';

    XLS.Filename := 'D:\output.xlsx';
    XLS.CompressStrings := False;
    XLS.Version := xvExcel2007;
    XLS.Write;
  finally
    FreeAndNil(XLS);
  end;
end;
And the output is still the same:

Code: Select all

Kôvŕgň Kŕlmŕn
陰茎 Kôvàgò Kàlmàn
Am I doing something wrong?

Re: Unicode character issue

Posted: Fri Apr 24, 2015 3:26 pm
by larsa
Hello

You must set CompressStrings before you add any strings. It takes effect immediately, not just when you write the file.

Re: Unicode character issue

Posted: Fri Apr 24, 2015 3:42 pm
by CareAll
Thank you, it's working now.