PageSize for TFlexCelPreviewer

How set "real" page size for TFlexCelPreviewer?

I want preview without any transfering to new lines.

My code
procedure TForm1.ToolButtonQueryClick(Sender: TObject);
var FileName: string;
begin
  Xls:=TXlsFile.Create(1, false);
  FileName:='C:\\Users\\bla-bla-bla\\report.xlsx';
  Xls.Open(FileName); // yes, need error check - no care
  setVisualPreviewer(Xls, FlexCelPreviewer1);
end;


procedure TForm1.setVisualPreviewer(myExcelFile: TExcelFile;
      myFlexCelPreviewer: TFlexCelPreviewer);
var
  myFixedSize: TPaperDimensions;
  m: TXlsMargins;
  ImgExport: TFlexCelImgExport;
  rectangleCoords: TUIRectangle;
begin
  ImgExport:=TFlexCelImgExport.Create(myExcelFile, false);
  myFlexCelPreviewer.Document:=ImgExport;


  // set zero margins
  m:=TXlsMargins.Create(0, 0, 0, 0, 0, 0);
  myExcelFile.SetPrintMargins(m);


  // make seperation smaller
  FlexCelPreviewer1.PageXSeparation:=1; FlexCelPreviewer1.PageYSeparation:=1;


  // get rectangle with data
  rectangleCoords:=myExcelFile.CellRangeDimensions(0, 0, 0, 0, true);
  myFixedSize:=ImgExport.PageSize;
  myFixedSize.Width:=rectangleCoords.Width; // wrong!!! width - too small
  // myFixedSize.Width:=rectangleCoords.Width+400; // good, but why 400???
  myFixedSize.Height:=rectangleCoords.Height;
  ImgExport.PageSize:=myFixedSize;
  // update preview
  myFlexCelPreviewer.InvalidatePreview;end;

I get this https://imgur.com/a/U8qHg
But I want this https://imgur.com/a/HyVMX
How I can calculate right width for page?

Hi,
This is just an unfortunate mix up of units. We try to keep the units Excel uses everywhere, but sadly Excel seems to use a different unit in every little thing.
In particular, the sizes in myFixedSize.Width are in inches/100 (because that is how Excel measures page sizes): http://www.tmssoftware.biz/flexcel/doc/vcl/api/FlexCel.Core/TPaperDimensions/

But, the size returned by CellRangeDimensions is in points (1/72 of an inch, points are in what most measurements are done): http://www.tmssoftware.biz/flexcel/doc/vcl/api/FlexCel.Core/TExcelFile/CellRangeDimensions.html

So that's the root of the problem. For some reason, Excel uses 1/100 of an inch for page sizes (and page margins I think), instead of 1/72 as used in most other places. So to fix it, you need to convert from 1/72 of an inch to 1/100 of an inch. The code would end up being:


myFixedSize.Width:=rectangleCoords.Width * 100.0 / 72.0;
myFixedSize.Height:=rectangleCoords.Height * 100.0 / 72.0;



Solved. Thanks.