Column Width Calculation

Use the TExportCell.CalculateColWidth property.

Set TExportCell.CalculateColWidth to true if the column width should be calculated automatically from the cell text.
Applicable only if WrapText = False, Orientation = efoLeftToRight, Rotation = 0 and ColSpan = 1.
If more cells within a column have CalculateColWidth = True, the maximum width from the cells is calculated.
Important: Column width and row height calculation works also for single-line cells with rich formatting. Multi-line cells with rich formatting are calculated like they were without formatting.

Column width calculation can't be used in the on-the-fly export.

See the code sample below.

uses
  {...}, OExport, OExport_Vcl, OExport_VclForms;

procedure TForm1.BtnTestClick(Sender: TObject);
var
  xExport: TOExport;
  I, L: Integer;
begin
  xExport := TOExport.Create;
  try
    with xExport.AddWorkSheet('ColWidth Calculation') do
    begin
      AddRow.AddCellString(Title).SetFontSize(20);
      AddRow;

      with AddRow do begin
        AddCellString('Long text, long text').SetCalculateColWidth;
      end;
      with AddRow do begin
        AddCellString('Short text').SetCalculateColWidth;
      end;
    end;

    xExport.SaveToFileWithDialog;
  finally
    xExport.Free;
  end;
end;
Categories