XLSReadWriteII 5 destroys xls strings when writing TWideMemo
Posted: Thu Mar 10, 2016 11:13 am
Hi, I am using Delphi XE10 on windows7 and I've built an application in which I try to create an xls file with XLSReadWriteII 5 component.
Specifically I am reading data that has been stored previously in an sql table and exporting it to a xls file.
Now, while everything works fine with ASCII characters, when I try to read (and thus write to the relative worksheet) Unicode data I am facing problem whenever I have to parse ntext fields. As all we know ntext sql's fields are handled by Delphi as TWideMemo fields, which is the appropriate data-type field to read Unicode data.
However, XLSReadWriteII 5 component not only does not write TWideMemo field's value in the xls file, but worst, it destroys any string data in any cell of the file that previously has written itself leaving only untouchable any numeric-type data.
And the most bizzare of all is that it does not creating any error during the writing procedure, which i would be able to catch using a try-except scheme and then try to solve it.
On the contrary, it executes the appropriate procedure like everything is fine (as it would be if writing ASCII characters data) and then when you try to open the xls file (either with excel or open-office), it gives you a couple of warning messages and after that you can only see cells with numeric data type and no string at all !!!
Here I give you the code which I use in my application:
I Also have to say that the data which I store in the ntext field of my sql table is being provided through an RTF Edit-box in the relevant form, so that to be able giving specific formatting to the UNICODE text I want to store (In cases I want to give specific format like Bold, Underline etc...).
Maybe this is the reason of the problem ... I don't know...
Is there any way to solve this problem ?
Thank you in advance
Specifically I am reading data that has been stored previously in an sql table and exporting it to a xls file.
Now, while everything works fine with ASCII characters, when I try to read (and thus write to the relative worksheet) Unicode data I am facing problem whenever I have to parse ntext fields. As all we know ntext sql's fields are handled by Delphi as TWideMemo fields, which is the appropriate data-type field to read Unicode data.
However, XLSReadWriteII 5 component not only does not write TWideMemo field's value in the xls file, but worst, it destroys any string data in any cell of the file that previously has written itself leaving only untouchable any numeric-type data.
And the most bizzare of all is that it does not creating any error during the writing procedure, which i would be able to catch using a try-except scheme and then try to solve it.
On the contrary, it executes the appropriate procedure like everything is fine (as it would be if writing ASCII characters data) and then when you try to open the xls file (either with excel or open-office), it gives you a couple of warning messages and after that you can only see cells with numeric data type and no string at all !!!
Here I give you the code which I use in my application:
Code: Select all
Procedure WriteDataToCell(adoQ:Tadoquery;row,col,fcol:integer);
var inh:string; data_type:TfieldType; XLappSun:TXLSReadWriteII5; sheetSun:Txlsworksheet;
begin
sheetsun:=xlappsun.SheetByName('sheet1');
data_type:=AdoQ.Fields[fcol].DataType;
case data_type of
ftdate,fttime,ftdatetime,ftTimeStamp:
begin
inh:= formatdatetime('dd/mm/yyyy',AdoQ.Fields[fcol].value);
sheetsun.asdatetime[col,row-1]:=AdoQ.Fields[fcol].value+0;
end;
ftboolean: begin
case AdoQ.Fields[fcol].asboolean of
true : sheetsun.AsInteger[col,row-1]:=1;
false: sheetsun.AsInteger[col,row-1]:=0;
end;
end;
ftSmallint,ftInteger,ftWord,ftAutoInc,ftLargeint:
begin
sheetsun.asinteger[col,row-1]:=AdoQ.Fields[fcol].asinteger;
end;
ftmemo,ftFmtMemo,ftwideMemo:
begin
try
sheetsun.Asstring[col,row-1]:=AdoQ.Fields[fcol].AsString ;
except
sheetsun.Asstring[col,row-1]:='*****';
end;
end;
ftblob,ftgraphic :
begin
sheetsun.Asstring[col,row-1]:='';
end;
ftFloat,ftCurrency,ftBCD:
begin
sheetsun.AsFloat[col,row-1]:=AdoQ.Fields[fcol].Value;
end;
else
try
sheetsun.Asstring[col,row-1]:=AdoQ.Fields[fcol].AsString;
except
sheetsun.Asstring[col,row-1]:='*****';
end;
end;
end;
Maybe this is the reason of the problem ... I don't know...
Is there any way to solve this problem ?
Thank you in advance