Open excel file with all sheets and with manual zoom lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- totya · 2016-12-19 19:43 Hi! http://forum.lazarus.freepascal.org/index.php/topic,34156.15.html and \examples\visual\zoom\zoomdemo.lpr works correctly. But how can I load any excel file with all sheets, and with (manual) zoom value (on all sheets)? Thanks! ---------------------------------------------------------------------- totya · 2016-12-19 21:29 I tried this simple code, I don't see any double draw effect with it... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,  fpspreadsheetctrls, fpspreadsheetgrid;  //fpstypes, fpsNumFormat, fpsReaderWriter type   { TForm1 }   TForm1 = class(TForm)    MainMenu1: TMainMenu;    LoadMenuItem: TMenuItem;    sWorkbookSource1: TsWorkbookSource;    sWorkbookTabControl1: TsWorkbookTabControl;    sWorksheetGrid1: TsWorksheetGrid;    procedure FormCreate(Sender: TObject);    procedure LoadMenuItemClick(Sender: TObject);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  sWorkbookTabControl1.WorkbookSource:= sWorkbookSource1;  sWorksheetGrid1.WorkbookSource:= sWorkbookSource1;end; procedure TForm1.LoadMenuItemClick(Sender: TObject);var  i: integer;begin  with sWorkbookSource1 do  begin    AutodetectFormat:= true;    FileName:='C:\Tmp\workbook_test.xls';     for i:=0 to Workbook.GetWorksheetCount-1 do      Workbook.GetWorksheetByIndex(i).ZoomFactor:= 1.5;  end;end;  end. ---------------------------------------------------------------------- wp · 2016-12-19 22:26 Quote from: totya on December 19, 2016, 08:43:57 pmBut how can I load any excel file with all sheets, and with (manual) zoom value (on all sheets)? I modified the zoom demo in the current revision to show how this is done. Look at TMainForm.LoadFile: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         book.ReadFromFile(AFilename, AFormatID);        // If you want to override the zoom factor of the file set it before        // assigning the worksheet to the grid.        for i:=0 to book.GetWorksheetCount-1 do        begin          sheet := book.GetWorksheetByIndex(i);        sheet.ZoomFactor := edZoom.Value / 100;        end;//        book.GetFirstWorksheet.ZoomFactor := edZoom.Value / 100;     // <--- this is the old version loading only the first sheet        // Load the first worksheet into the grid.        Grid.LoadFromWorkbook(book, 0); The demo now also has two buttons to navigate between the sheets of the same workbook without using a TsWorkbookTabControl. ---------------------------------------------------------------------- totya · 2016-12-20 05:44 Hi! Very thank you for your answer and for then demo code! But now I prefer TsWorkbookTabControl, because I see immediately how many sheets available, and I can change easily between sheets. Both (small) problem with two solutions, these uses one grid really, so the exact selected cell "screeen" position are lost when I switch between sheets. For example, I select cell in one sheet of the middle of the screen, but if I change to other sheet, and back to this sheet, the selected cell position is the top or bottom of the screen. Okay, I know, if I want untouched grids, I need (really) different grids of every sheets. ---------------------------------------------------------------------- wp · 2016-12-20 08:59 Quote from: totya on December 20, 2016, 06:44:59 amBoth (small) problem with two solutions, these uses one grid really, so the exact selected cell "screeen" position are last when I switch between sheets. For example, I select cell in one sheet of the middle of the screen, but if I change to other sheet, and back to this sheet, the selected cell position is the top or bottom of the screen. Okay, I know, if I want untouched grids, I need (really) different grids of every sheets. The worksheet stores the col/row indexes of the selected cell internally. Therefore, the selected cell is restored when you switch in the grid to another sheet and return to the previous one. The selected cell may scroll to another position, though, i.e. the top/left cell can be changing. Therefore, you should setup an array of TPoint storing the row/col of the top left cell for each sheet in the workbook (sWorksheetGrid.TopLeft). Before the tabcontrol activates another sheet the TopLeft cell position should be stored in this array, and after the tabcontrol has activated a new grid the TopLeft cell should be restored from this array for the newly active sheet. I don't have the time now to play with this idea, but I think all events needed are available. ---------------------------------------------------------------------- totya · 2016-12-20 22:58 Hi! Thank you for this information! ---------------------------------------------------------------------- totya · 2016-12-22 21:00 The second "cosmetic" problem with the "common grid" the unnecessary lines in sheets. Code example: http://forum.lazarus.freepascal.org/ind ex.php/topic,35182.msg232237.html#msg232237 For example the first sheet use 1000 excel row, the second only 100. But If I open these sheets, all sheets contain 1000 lines... but 900 lines are unexisted and unnecessary in the second sheet, so the scroll bar show incorrect information from the sheet... I think the really separate grid is the best solution... Thanks again! ---------------------------------------------------------------------- wp · 2016-12-23 17:12 The new revision fixes a few bugs and now it is possible to switch from sheet to sheet, but the active cell of the new sheet remains the one stored in the worksheet. Moreover, the lines of columns and rows automatically adjusts to the value given by the worksheet. But note that the grid always assumes a minimum of 26 columns (single-letter characters 'A'..'Z') and 100 rows even if the worksheet is smaller. I found this looks better than a 1-cell-only grid, in an extreme case. If required I could declare DEFAULT_ROW_COUNT (=100) and DEFAULT_COL_COUNT (=26) as variables (they are constants now). ---------------------------------------------------------------------- totya · 2016-12-23 19:31 Hi! Thank you for your job! With DEFAULT_ROW/COL_COUNT = 1 for me the result is perfect, I don't see unneded empty lines. But these constants, so I need to modify these every times, if this svn source file will change. I see you works too with remain scroll position too, so this doesn't work every case. I try to create sample... if I can. Because this is the job file, and I can't share it. Perhaps I can tell, I see the problem on the second sheet, and this sheet use own backgorund colour (and cell size changed because these lines uses background colours). So, In excel, cell size doesn't changed if the colour is changed... ---------------------------------------------------------------------- wp · 2016-12-23 21:01 In the new revision DEFAULT_ROW_COUNT and DEFAULT_COL_COUNT are variables now. Change them to the values needed directly in your application before you load the file. ---------------------------------------------------------------------- totya · 2016-12-23 21:03 Thank you, I use it few minutes ago, when the rev 5561 arrived.