Page 1 of 1

TXLSWorksheet.AutoWidthCol ignores IsWrapText property

Posted: Tue Mar 13, 2018 10:11 am
by Moisha
Hi.

Procedure TXLSWorksheet.AutoWidthCol calculates column width using function TCanvas.TextWidth.
This function works for single lines only.

I suggest the next improvement for function TXLSWorksheet.AutoWidthCol:

Code: Select all

var 
  tw: integer;
  r: TRect;
begin
.......
        S := GetAsFmtString(ACol,FCells.IterCellRow);
        if XF.Alignment.IsWrapText then
        begin
          ZeroMemory(@r, SizeOf(r));
          DrawTextEx(Canvas.Handle, PChar(S), -1, r, DT_CALCRECT, nil);
          if XF.Alignment.Rotation in [90,180,255] then // Vertical
            tw := r.Height
          else
            tw := r.Width;
        end
        else
        begin
          if XF.Alignment.Rotation in [90,180,255] then // Vertical
            tw := Canvas.TextHeight(S)
          else
            tw := Canvas.TextWidth(S);
        end;
        W := tw + TM.tmAveCharWidth + 5;
Procedure TXLSWorksheet.AutoHeightRow works better, it can handle IsWrapText and multiline cells but only if XF.Alignment.Rotation = 0. Thus same improvement suggested.

When XF.Alignment.Rotation = 255 even improved functions works pretty bad.

Ragards
Moisha.

Re: TXLSWorksheet.AutoWidthCol ignores IsWrapText property

Posted: Wed Mar 21, 2018 8:59 am
by larsa
Hello

Thank you. I will include this in the next update.