anchor.diff:                  end;
                 end;
               end
  -            else if ColSpan > Span then
  -              More := True {set if need another iteration}
  -          end;
  +          else
  +            //BG, 29.01.2011: at this point: CellObj.ColSpan <> Span
  +            if Span = 1 then
  +            begin
  +              //BG, 29.01.2011: at this point: in the first loop with a CellObj.ColSpan > 1.
  +
  +              // Reduce too large ColSpans, or the column loop tuning will not process all cells.
  +              if CellObj.ColSpan > NumCols - I then
  +                CellObj.ColSpan := NumCols - I;
  +
  +              // Collect data for termination and tuning.
  +              if MaxSpans[J] < CellObj.ColSpan then
  +              begin
  +                MaxSpans[J] := CellObj.ColSpan; // data for tuning
  +                if MaxSpan < MaxSpans[J] then
  +                  MaxSpan := MaxSpans[J]; // data for termination
  +              end;
  +            end;
         end;
       end;
       Inc(Span);
  -  end;
  -
  -  TotalMaxWidth := 0; TotalMinWidth := 0;
  +  until Span > MaxSpan;
  +
  +  TotalMaxWidth := 0;
  +  TotalMinWidth := 0;
     for I := 0 to NumCols - 1 do
     begin
       Inc(TotalMaxWidth, MaxWidths[I]);
  
positive.code:     MinWidths[I] := 0;
      Percents[I] := 0;
    end;
    SetLength(Heights, 0);
    Span := 1;
    More := True;
    while More do
    begin
      More := False;
      for J := 0 to Rows.Count - 1 do
      begin
        Cells := Rows[J];
        for I := 0 to Cells.Count - 1 do
        begin
          CellObj := Cells[I];
          if CellObj <> nil then
            with CellObj do
            begin
              if ColSpan = Span then
              begin
                PCWidth := 0;
                if WidthAttr > 0 then
                  if AsPercent then
                    PCWidth := WidthAttr
                  else if TheWidth > 0 then
                    PCWidth := Math.Min(1000, MulDiv(WidthAttr, 1000, TheWidth));
  
  
negative.code: var
    I, J, Min, Max, N, Span, Addon, Distributable, TotalPC, Accum,
      ExcessMin, ExcessMax, NonPC, PCWidth, NewTotalPC: Integer;
    Cells: TCellList;
    CellObj: TCellObj;
    MaxSpans: array of Integer;
    MaxSpan: Integer;
  begin
  {Find the max and min widths of each column}
    for I := 0 to NumCols - 1 do
  