may be small mistakes? in XLS RW 3 (My fixes below)

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
vvc
Posts: 4
Joined: Mon Jan 23, 2006 6:25 pm

may be small mistakes? in XLS RW 3 (My fixes below)

Post by vvc »

1) Creating XLS with current regional settings, but not 1200 codepage
procedure TRecordStorageGlobals.SetDefaultData;
begin
.....
{$IFDEF VVC}
PCODEPAGE := AddDefRecWord(BIFFRECID_CODEPAGE, GetACP());
{$ELSE}
PCODEPAGE := AddDefRecWord(BIFFRECID_CODEPAGE,$04B0);
{$ENDIF}
......

2) Bad data when writing unicode non english strings.

procedure TXLSReadII.RREC_LABEL;
var
i: integer;
P: PWordArray;
WS: WideString;
begin
InsertRecord := False;
with PRecLABEL(PBuf)^ do begin
if FXLS.Version > xvExcel97 then
FXLS.Sheets[FCurrSheet].IntWriteSSTString(Col,Row,FormatIndex,ByteStrToWideString(@Data[0],Len))
else begin
SetLength(WS,Len);
if Data[0] = 0 then begin
{$IFDEF VVC}
MultiByteToWideChar(FXLS.CodePage,MB_PRECOMPOSED,Pointer(Integer(@Data)+1),Len-1,PWideChar(WS),Len*2);
{$ELSE}
for i := 1 to Len do
WS := WideChar(Data);
{$ENDIF}
end
else if Data[0] = 1 then begin
P := @Data[1];
for i := 0 to Len - 1 do
WS[i + 1] := WideChar(P);
end
else begin
{$IFDEF VVC}
MultiByteToWideChar(FXLS.CodePage,MB_PRECOMPOSED,@Data,Len,PWideChar(WS),Len*2);
{$ELSE}
for i := 0 to Len - 1 do
WS[i + 1] := WideChar(Data);
{$ENDIF}
end;
FXLS.Sheets[FCurrSheet].IntWriteSSTString(Col,Row,FormatIndex,WS);
end;
end;
end;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Post by larsa »

Hello

Sorry, but your changes are completly wrong. Do not use them.

Excel uses unicode strings in order to display non-latin characters. What you shall do is to assign a correct unicode string to the cell with the AsString property. If you have done so, and your characters don't shows correct in excel, the problem is probably that there is no font installed that can handle the characters.


Lars Arvidsson
vvc
Posts: 4
Joined: Mon Jan 23, 2006 6:25 pm

Post by vvc »

I'm remember!! This changes was required when i read xls files in old formats (xls 5...), in which strings placed in non-unicode formats, but non English codepage. Without this changes component read them as FIXED $4B0 codepage and as result - incorrect..
vvc
Posts: 4
Joined: Mon Jan 23, 2006 6:25 pm

Another yet

Post by vvc »

In source

function TCellFormat.FormatIsDateTime: boolean;
begin
Result := FXF.NumFmtIndex in [$0E,$14];
end;

may must be?
function TCellFormat.FormatIsDateTime: boolean;
begin
Result := FXF.NumFmtIndex in [$0E..$14];
end;

or even
function TCellFormat.FormatIsDateTime: boolean;
begin
Result := FXF.NumFmtIndex in [$0E..$16];
end;
Post Reply