Here some experiments with row height:
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
fpstypes, fpsutils, fpspreadsheet, fpsallformats;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
const
t00 = '123';
t01 = '1234';
t10 = 'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
+'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM';
t11 = 'abc';
TargetDir = 'C:\temp99\'; // should be harmless
var
myWB: TsWorkbook;
myWS: TsWorksheet;
procedure TForm1.FormShow(Sender: TObject);
begin
MyWB := TsWorkbook.Create;
MyWS := MyWB.AddWorksheet('My_Table');
CreateDir(TargetDir);
MyWS.WriteText(0,0,t00); // fill with text
MyWS.WriteText(0,1,t01);
MyWS.WriteText(1,0,t10);
MyWS.WriteText(1,1,t11);
MyWs.WriteWordWrap(1,0,true);
// case 1
MyWs.WriteRowHeight (1, 0, suLines, rhtAuto);
MyWB.WriteToFile(TargetDir + 'case1.xlsx',true);
// case 2
MyWs.WriteRowHeight (1, 5, suLines, rhtauto);
MyWB.WriteToFile(TargetDir + 'case2.xlsx',true);
// case 3
MyWs.WriteRowHeight (1, 30, suLines, rhtauto);
MyWB.WriteToFile(TargetDir + 'case3.xlsx',true);
// case 4
MyWs.WriteRowHeight (1, 5, suLines, rhtCustom);
MyWB.WriteToFile(TargetDir + 'case4.xlsx',true);
// case 5
MyWs.WriteDefaultRowHeight(1,suLines);
MyWB.WriteToFile(TargetDir + 'case5.xlsx',true);
MyWB.Free;
end;
end.
This code generates 5 spreadsheet files.
Issue 1: When you open each one (I used LO Calc), the result is that there is no automatic adaptation of the row height to the cell content, even with rhtAuto.
Also, the row size is fixed. Adding additional characters in Calc to the big cell does not auto-expand the row heigth.
Issue 2:
When any of the files is opened in Calc and the row with the large cell is right-clicked, clicking Optimal Row Height, the row height is expanded as expected. Saving the file and reopening it demonstrates that the auto-row height setting is persistent. So there must be a flag somewhere in the file for each row indicating that the row height is to be automatically adjusted.
I tested this for .xlsx, .xls and .ods files.
My question is: is there a way to set this flag with fpspreadsheet?
That would free fpspreadsheet from elaborate calculations. Indeed, it is Excel or Calc that do the calculation.
Since there are no visuals active in my fpspreadsheet application, this seems optimal.
Of course, I could have misunderstood what fpspreadsheet does.
Kind regards,