Forum > FPSpreadsheet
TsWorbookSource
straetch:
I have a workbook with one sheet.
I want to display items with a TsWorksheetGrid.
So I included the TsWorksheetGrid and a TsWorkbookSource.
The grid is linked to the WorkbookSource.
I am confused how to link the workbooksource to the workbook.
My code looks like this:
BestandenWB := TsWorkbook.Create;
BestandenWS := BestandenWB.AddWorksheet('Bestandenlijst');
sWorkbookSource.LoadFromWorkbook(BestandenWB); // link to the grid
But I get an SIGSEGV on the last statement.
I experimented with TsWorkbookSource.SelectWorksheet. Does not work.
In the tutorial I do not find how to do that for newly created workbooks. For workbooks loaded from file it is clear.
I must be missing something trivial.
Using laz_fpspreadsheet_visual 1.14.0.0
wp:
Can you post a simple project to demonstrate the issue?
straetch:
The project contains a sWorkbookSource and grid. The grid is linked to the sWorkbookSource.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var BestandenWB: TsWorkBook; BestandenWS: TsWorkSheet;begin BestandenWSGrid: TsWorksheetGrid; BestandenWB := TsWorkbook.Create; BestandenWS := BestandenWB.AddWorksheet('Bestandenlijst'); sWorkbookSource.LoadFromWorkbook(BestandenWB); BestandenWSGrid.Clear;end; The program generates a SIGSEGV on the statement BestandenWSGrid.Clear;
The last item on the stack points at fpspreadsheetgrid.pas(sourcevisual\) at row 6373, Function GETWORKBOOKSOURCE(0x0).
If I remove the last instruction, then the problem is gone.
Does that mean that, once the grid is linked to the workbooksource, I cannot work directly on the grid?
straetch:
Thinking further.
I guess the behaviour of fpspreadsheet is correct.
The content of the grid follows the content of the active worksheet via the sWorkbooksource.
So I can only change the content of the grid by changing the content of the worksheet.
Correct?
wp:
Yes. Unlike TStringGrid, the WorksheetGrid does not contain any data. It reads and writes its data (and formatting) from/to the underlying worksheet.
If you only need a WorksheetGrid on your form and no other visual spreadsheet controls, you can skip the WorkbookSource because the Grid contains an internal WorkbookSource which becomes active when no other WorkbookSource is connected. So, you simply place a WorksheetGrid on the form, and let the user type in his/her data values and formatting. Or you pre-fill the grid by yourself by setting the WorksheetGrid.Cells[c, r]. At the end you simply save by calling WorksheetGrid.SaveToFile(_file_name_, _file_format_, true) (the "true" is for overwriting an already-existing file). Before that you may want to specify the name of the worksheet which contains the grid:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses [...], fpSpreadsheetGrid, fpsTypes, xlsxOOXML; procedure TForm1.Button1Click(Sender: TObject);begin sWorksheetGrid1.Autocalc := true; sWorksheetGrid1.Cells[1, 1] := 'ABC'; sWorksheetGrid1.CellFont[0, 0].Style := [fsBold]; sWorksheetGrid1.Cells[1, 2] := '=sqrt(2)'; // requires sWorksheetGrid1.AutoCalc := true somewhere... sWorksheetGrid1.Worksheet.Name := 'This is a test'; sWorksheetGrid1.SaveToSpreadsheetFile('test.xlsx', sfOOXML, true);end;
Navigation
[0] Message Index
[#] Next page