TXLSWorksheet.AutoWidthCol ignores IsWrapText property

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
Moisha
Posts: 18
Joined: Wed Apr 06, 2016 1:00 pm

TXLSWorksheet.AutoWidthCol ignores IsWrapText property

Post 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.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: TXLSWorksheet.AutoWidthCol ignores IsWrapText property

Post by larsa »

Hello

Thank you. I will include this in the next update.
Lars Arvidsson, Axolot Data
Post Reply