Page 1 of 1

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

Posted: Tue May 29, 2007 2:02 pm
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;

Posted: Wed May 30, 2007 1:29 pm
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

Posted: Fri Jul 06, 2007 9:59 am
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..

Another yet

Posted: Fri Jul 06, 2007 10:01 am
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;