Unicode character issue

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
CareAll
Posts: 28
Joined: Mon Jun 24, 2013 9:30 am

Unicode character issue

Post 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.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Unicode character issue

Post 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.
Lars Arvidsson, Axolot Data
CareAll
Posts: 28
Joined: Mon Jun 24, 2013 9:30 am

Re: Unicode character issue

Post 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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Unicode character issue

Post by larsa »

Hello

The output is: "Kôvàgò Kàlmàn"
Lars Arvidsson, Axolot Data
CareAll
Posts: 28
Joined: Mon Jun 24, 2013 9:30 am

Re: Unicode character issue

Post 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.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Unicode character issue

Post 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.
Lars Arvidsson, Axolot Data
CareAll
Posts: 28
Joined: Mon Jun 24, 2013 9:30 am

Re: Unicode character issue

Post by CareAll »

I will try it, thank you.
CareAll
Posts: 28
Joined: Mon Jun 24, 2013 9:30 am

Re: Unicode character issue

Post 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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Unicode character issue

Post by larsa »

Hello

You must set CompressStrings before you add any strings. It takes effect immediately, not just when you write the file.
Lars Arvidsson, Axolot Data
CareAll
Posts: 28
Joined: Mon Jun 24, 2013 9:30 am

Re: Unicode character issue

Post by CareAll »

Thank you, it's working now.
Post Reply