I am using v5.20.49 and use the AutoWidthCol function to adjuste the cell width of user defined cells like '125,5 KB'.
Unfortunately most of the time the widest cell is cut of a bit.
I have debuged the code and the problem is caused by a wrong while loop in XLSMask5.pas function TExcelMask.FormatNumberNumber(FD: TFormatData; Value: double): AxUCString;
lines 728 - 733:
Code: Select all
j := 0;
while (j < Length(Data[i].S)) and (ResPos < SZ_RESBUF) do begin
Res[ResPos] := Data[i].S[j];
Inc(j);
Inc(ResPos);
end;
Strings are not zero based in delphi. I think the code have to be:
j := 1;
while (j <= Length(Data.S)) and (ResPos < SZ_RESBUF) do begin
Res[ResPos] := Data.S[j];
Inc(j);
Inc(ResPos);
end;
Also please take a look into XLSSheetData5.pas function TXLSWorksheet.AutoWidthCol(const ACol: integer): integer; lines 1528 and 1530:
Code: Select all
W := Canvas.TextWidth(GetAsFmtString(ACol,FCells.IterCellRow)) + TM.tmAveCharWidth + 5;
Code: Select all
+ TM.tmAveCharWidth
I am sorry for my bad english but I hope you understand the problem. If s.th. is not clear to you, please ask me.
I have also a question regarding the same lines (1528/1530): why do you add "+5" to the text width?
I guess you add this constant to the width because a few lines below (line 1538) you call
Code: Select all
FColumns[ACol].PixelWidth := Result;
The setter of the property PixelWith is implemented like this:
Code: Select all
procedure TXLSColumn.SetPixelWidth(const AValue: integer);
begin
SetWidth(Round(Trunc((AValue - 5) / FOwner.FStyles.StdFontWidth * 100 + 0.5) / 100) * 256);
end;
Also in my tests it seems that +5 is not sufficient. The values in the cells are still cut of. Can you fix this (e.g. using a higher value like +15, or set it to +10 but remove the -5 from the setter)?
Thanks once again for your help.