Recent

Author Topic: auto-adjust only number of rows with data  (Read 827 times)

Ericktux

  • Full Member
  • ***
  • Posts: 235
auto-adjust only number of rows with data
« on: May 13, 2021, 11:31:29 am »
Hello friends, when I load an excel with several rows I use the option to auto-adjust "sWorksheetGrid -> AutoExpand (only aeNavigation marked)" it works for me when I have several rows, but when I have only 5 rows it always gives me 10 or 11 rows by default.

How can I solve this friends, greetings

attached example image

wp

  • Hero Member
  • *****
  • Posts: 8351
Re: auto-adjust only number of rows with data
« Reply #1 on: May 13, 2021, 11:55:03 am »
If you want to see the grid lines only within the range occupied by data you should set the grid's ColCount and GrowCount accordingly. If you have aeNavigation in the AutoExpand property the range expands when you navigate outside the given range - I don't know if this is what you want. aeData is sufficient, in my opinion.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   nc, nr: Cardinal;
  4.   sheet: TsWorksheet;
  5. begin
  6.   sWorksheetGrid1.LoadFromSpreadsheetFile('test.xlsx', sfOOXML);
  7.   sWorksheetGrid1.AutoExpand := [aeData];
  8.   sheet := sWorksheetGrid1.Worksheet;
  9.   nc := sheet.GetLastColIndex;
  10.   nr := sheet.GetlastRowIndex;
  11.   sWorksheetGrid1.ColCount := nc;
  12.   sWorksheetGrid1.RowCount := nr;
  13. end;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018