Recent

Author Topic: Hide SpreadsheetGrid Headers not working?  (Read 1784 times)

Bert_Plitt

  • New member
  • *
  • Posts: 24
Hide SpreadsheetGrid Headers not working?
« on: February 28, 2019, 07:14:55 pm »
What am I missing?  I have installed "fpspreadsheet-1.10.1" and am testing "demo_ctrls.lpi".  In TsWorksheetGrid, if I set ShowHeaders to False, the column and row headers are not visible at design time.  But at run time, the headers are displayed.  Is this a bug?  How do I hide the headers at run time.

Running Windows 10, Lazarus 1.8.4, FPC 3.0.4

wp

  • Hero Member
  • *****
  • Posts: 5652
Re: Hide SpreadsheetGrid Headers not working?
« Reply #1 on: February 28, 2019, 10:49:14 pm »
OK I see. The ShowHeader is a remainder of early experiments with the grid, it is a shortcut to access the Worksheet.Option soShowHeader; this means that the Showheader adjusts itself to the value stored in the worksheets, and you can use this property AFTER LOADING to change the setting of the file. This will have to be fixed, but I don't know yet how this can be done in a compatible way. While ShowHeaders now is a boolean property I think it should have three values. ForceOff, ForceOn, Worksheet.

What you can do at the moment is to write an OnCreate handler for the form which turns the headers of the default worksheet off:
Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   sWorksheetGrid1.ShowHeaders := false;
  4. end;
and you must do the same after loading a file, in DemoCtrls at the end of FileOpen1Accept:
Code: Pascal  [Select]
  1. procedure TForm1.FileOpen1Accept(Sender: TObject);
  2. begin
  3.   sWorkbookSource1.AutodetectFormat := false;
  4.   case FileOpen1.Dialog.FilterIndex of
  5.     1: sWorkbookSource1.AutoDetectFormat := true;         // All spreadsheet files
  6.     2: sWorkbookSource1.AutoDetectFormat := true;         // All Excel files
  7.     3: sWorkbookSource1.FileFormat := sfOOXML;            // Excel 2007+
  8.     4: sWorkbookSource1.FileFormat := sfExcel8;           // Excel 97-2003
  9.     5: sWorkbookSource1.FileFormat := sfExcel5;           // Excel 5.0
  10.     6: sWorkbookSource1.FileFormat := sfExcel2;           // Excel 2.1
  11.     7: sWorkbookSource1.FileFormat := sfOpenDocument;     // Open/LibreOffice
  12.     8: sWorkbookSource1.FileFormat := sfCSV;              // Text files
  13.   end;
  14.   sWorkbookSource1.FileName :=FileOpen1.Dialog.FileName;  // This loads the file
  15.   sWorksheetGrid1.ShowHeaders := false;
  16. end;
There could be some flicker immediately after loading because the worksheet is displayed briefly with headers which are turned off immediately afterwards.

This could be avoided if you load the workbook into a local variable, remove the boShowHeaders from its Options, and only then pass it to the workbook source:
Code: Pascal  [Select]
  1. procedure TForm1.FileOpen1Accept(Sender: TObject);
  2. var
  3.   wb: TsWorkbook;
  4.   sh: TsWorksheet;
  5.   i: Integer;
  6. begin
  7.   wb := TsWorkbook.Create;
  8.   case FileOpen1.Dialog.FilterIndex of
  9.     1: wb.ReadfromFile(FileOpen1.Dialog.FileName);  // all spreadsheet files --> autodetect
  10.     2: wb.ReadFromFile(FileOpen1.Dialog.FileName);  // all Excel files --> autodetect
  11.     3: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfOOXML);   // Exel 2007+
  12.     4: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel8);  // Excel 97-2003
  13.     5: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel5);  // Excel 5.0
  14.     6: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel2);  // Excel 2.1
  15.     7: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfOpenDocument);  // LibreOffice
  16.     8: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfCSV);     // Text files
  17.   else
  18.     wb.Free;
  19.     MessageDlg('File format not implemented.', mtError, [mbOk], 0);
  20.     exit;
  21.   end;
  22.   for i := 0 to wb.GetWorksheetCount - 1 do begin
  23.     sh := wb.GetWorksheetByIndex(i);
  24.     sh.Options := sh.Options - [soShowHeaders];
  25.   end;
  26.   sWorkbookSource1.LoadFromWorkbook(wb);
  27.   // Do not destroy wb here, it is needed by the WorkbookSource!
  28. end;
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Bert_Plitt

  • New member
  • *
  • Posts: 24
Re: Hide SpreadsheetGrid Headers not working?
« Reply #2 on: March 01, 2019, 04:31:31 am »
The workaround for hiding headers will work OK for me.  Now I think there is another problem in "demo_ctrls".

I believe that the width and height of sCellEdit1 in TsWorksheetGrid is supposed to track the changes is size of ToolBar3 (sCellEdit1 is alClient aligned).  Also, I believe the height of Panel2 should track the height of ToolBar3 (Panel2 is alLeft aligned).  At design time and run time the sizes of both sCellEdit1 and Panel2 do not change as the size of ToolBar3 changes.  Is this a bug or am I misunderstanding?

wp

  • Hero Member
  • *****
  • Posts: 5652
Re: Hide SpreadsheetGrid Headers not working?
« Reply #3 on: March 01, 2019, 06:05:33 pm »
Yes, this seems so be a limitation of using TToolbar as a container - almost all sizing and positioning properties do not work. I should have used a TPanel instead, like I did in "spready" (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/applications/spready/ - note that you must install additional components to use this demo).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Bert_Plitt

  • New member
  • *
  • Posts: 24
Re: Hide SpreadsheetGrid Headers not working?
« Reply #4 on: March 01, 2019, 06:14:31 pm »
Thanks.  I'll look at spready.

Bert_Plitt

  • New member
  • *
  • Posts: 24
Re: Hide SpreadsheetGrid Headers not working?
« Reply #5 on: March 02, 2019, 05:24:13 am »
OK, I downloaded spready and installed the extra required packages (I think).  Tried to compile spready but got error message in mainform: 'identifier not found "TCell"'.  Do I have a missing package?

wp

  • Hero Member
  • *****
  • Posts: 5652
Re: Hide SpreadsheetGrid Headers not working?
« Reply #6 on: March 02, 2019, 11:46:35 am »
I cannot confirm this error, neither with Laz trunk nor with Laz 1.8.4. In which unit does it arise? TCell is declared in unit fpsTypes.

There is an incompatibility with Laz 1.8.4, though, which is fixed in the current revision. Either download spready again, or open the file smain.lfm in an external editor and remove the line which specifies the property "FixedColWidth" of the grid (new in fpspreadsheet trunk).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Bert_Plitt

  • New member
  • *
  • Posts: 24
Re: Hide SpreadsheetGrid Headers not working?
« Reply #7 on: March 02, 2019, 07:43:34 pm »
WP -- I hate being a pest, but I think I got the wrong version of spready!  The file I got from SourceForge was "lazarus-ccr-svn-r3382-components-fpspreadsheet-examples-spready.zip".  It contains files with old dates (i.e. 2014)!  It does not have a file named smain.lfm; instead it has files named, e.g., mainform.lfm (7/26/2014), mainform.pas (7/26/2014), spready.lpi (7/25/2014), and spready.lpr (7/25/2014).

Can you give me exact (step by step) instructions on how to get the correct version of spready from SourceForge?

wp

  • Hero Member
  • *****
  • Posts: 5652
Re: Hide SpreadsheetGrid Headers not working?
« Reply #8 on: March 02, 2019, 08:02:08 pm »
I don't know if it's worth the effort for just a demo... I guess you are unfamiliar with svn, therefore i tell you the other way:

Click on "Download snapshot" on the site https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/. This gets you a snapshot of the entire Lazarus Code and Component Repository. Much more than you need... Unzip the download and delete everything that you don't want. spready is in the folder components/spready. In the folder components/fpsreadsheet you can also find the development version of fpspreadsheet.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Bert_Plitt

  • New member
  • *
  • Posts: 24
Re: Hide SpreadsheetGrid Headers not working?
« Reply #9 on: March 02, 2019, 11:08:03 pm »
OK.  Got the correct file now.  Spready compiles and runs OK.  Thanks for your help