Recent

Author Topic: Best way to determine if TsWorkSheetGrid has connection to spreadsheet  (Read 153 times)

dodgebros

  • Jr. Member
  • **
  • Posts: 92
Please pardon the subject line wording, not sure how to word my quesion.  I have a TsWorkSheetGrid that I run a process on and I need to know if the user has, shall we say, bond an actual spreadsheet file to it before the process is allowed to run.

At the present, I am checking to see if the TsWorkBookSource.filename property is populated.  Is that the best way to determine this?

Hope this makes sense,
TD

wp

  • Hero Member
  • *****
  • Posts: 7356
But a workbook can be created by code and can contain data without being saved...

Checking the sheet count does not work because the visual controls create an empty dummy sheet by default.

I think it's best to check the row and column count of the worksheet. If both are zero, it cannot contain any data:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   if (sWorkbookSource1.Workbook.GetWorksheetCount <= 1) and
  4.      ((sWorkbookSource1.Worksheet.GetLastRowIndex = 0) and (sWorkbookSource1.Worksheet.GetLastcolIndex = 0))  
  5.   then
  6.     Caption := 'empty';
  7. end;
« Last Edit: July 14, 2020, 07:09:25 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

dodgebros

  • Jr. Member
  • **
  • Posts: 92
Thank you wp, I'll try that,
TD

 

TinyPortal © 2005-2018