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:
procedure TForm1.FormCreate(Sender: TObject);
begin
sWorksheetGrid1.ShowHeaders := false;
end;
and you must do the same after loading a file, in DemoCtrls at the end of FileOpen1Accept:
procedure TForm1.FileOpen1Accept(Sender: TObject);
begin
sWorkbookSource1.AutodetectFormat := false;
case FileOpen1.Dialog.FilterIndex of
1: sWorkbookSource1.AutoDetectFormat := true; // All spreadsheet files
2: sWorkbookSource1.AutoDetectFormat := true; // All Excel files
3: sWorkbookSource1.FileFormat := sfOOXML; // Excel 2007+
4: sWorkbookSource1.FileFormat := sfExcel8; // Excel 97-2003
5: sWorkbookSource1.FileFormat := sfExcel5; // Excel 5.0
6: sWorkbookSource1.FileFormat := sfExcel2; // Excel 2.1
7: sWorkbookSource1.FileFormat := sfOpenDocument; // Open/LibreOffice
8: sWorkbookSource1.FileFormat := sfCSV; // Text files
end;
sWorkbookSource1.FileName :=FileOpen1.Dialog.FileName; // This loads the file
sWorksheetGrid1.ShowHeaders := false;
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:
procedure TForm1.FileOpen1Accept(Sender: TObject);
var
wb: TsWorkbook;
sh: TsWorksheet;
i: Integer;
begin
wb := TsWorkbook.Create;
case FileOpen1.Dialog.FilterIndex of
1: wb.ReadfromFile(FileOpen1.Dialog.FileName); // all spreadsheet files --> autodetect
2: wb.ReadFromFile(FileOpen1.Dialog.FileName); // all Excel files --> autodetect
3: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfOOXML); // Exel 2007+
4: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel8); // Excel 97-2003
5: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel5); // Excel 5.0
6: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfExcel2); // Excel 2.1
7: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfOpenDocument); // LibreOffice
8: wb.ReadFromFile(FileOpen1.Dialog.FileName, sfCSV); // Text files
else
wb.Free;
MessageDlg('File format not implemented.', mtError, [mbOk], 0);
exit;
end;
for i := 0 to wb.GetWorksheetCount - 1 do begin
sh := wb.GetWorksheetByIndex(i);
sh.Options := sh.Options - [soShowHeaders];
end;
sWorkbookSource1.LoadFromWorkbook(wb);
// Do not destroy wb here, it is needed by the WorkbookSource!
end;