Worksheet.PageLayout lazarus / 61-Beginners ---------------------------------------------------------------------- seghele0 · 2024-11-29 14:46 I'm trying to add a line with: "Worksheet.PageLayout.HorizontalCentered := True;" but I get ERROR: "Identifier idents no member HorizontalCentered ". Please help. 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 ………..uses  Windows,Dialogs, Interfaces, Classes, SysUtils, FileUtil,  Forms, Controls, ExtCtrls, StdCtrls, ComCtrls, Graphics, Menus,  Grids, Buttons, IniFiles,Printers, OSPrinters, PrintersDlgs,  DateUtils, Variants, lMessages, LCLProc, LCLType,  LCLIntf,  fpsexport, fpSpreadsheet, fpstypes, fpsUtils, xlsxooxml;      const  HEADER_FONT_SIZE = 11;   // in Points  DEFAULT_FONT_SIZE = 15;  // in Points  NICE_ROWHEIGHT_FACTOR = 1.5;  // adds extra margin to the cellvar                                         WORKBOOK: TsWorkbook;  WORKSHEET: TsWorksheet;  CELL: pCell;  Row: Integer;  // Row  Col: Integer;  // Column  tmpvalue: Single;  tmpColCountArr: array of Integer;   //col length array     …….……  Workbook := TsWorkbook.Create;  try    // Add a worksheet to the workbook    Worksheet := Workbook.AddWorksheet('Export from grid');    // Set default font for the workbook    Workbook.SetDefaultFont('Dejavu Sans Mono', DEFAULT_FONT_SIZE);    Worksheet.WriteDefaultRowHeight(DEFAULT_FONT_SIZE * NICE_ROWHEIGHT_FACTOR, suPoints);    // Set default column widths based on StringGrid column sizes    for Col := 0 to StringGrid1.ColCount - 1 do      Worksheet.WriteColWidth(Col, pxToPts(StringGrid1.ColWidths[Col], Screen.PixelsPerInch), suPoints);    // Configure the header row    for Col := 0 to StringGrid1.ColCount - 1 do    begin      // Write header text      Cell := Worksheet.WriteText(0, Col, StringGrid1.Cells[Col, 0]);      Worksheet.WriteHorAlignment(Cell, haCenter);       // Center horizontally      Worksheet.WriteVertAlignment(Cell, vaCenter);      // Center vertically      Worksheet.WriteBorders(Cell, [cbNorth, cbSouth, cbEast, cbWest]); // Add borders      Worksheet.WriteFontStyle(Cell, [fssBold]);         // Bold font      Worksheet.WriteFontSize(Cell, HEADER_FONT_SIZE);   // Set font size    Worksheet.WriteFontName(Cell, 'Dejavu Sans Mono'); // Set font name      Worksheet.WriteBackgroundColor(Cell, scYellow);    // Set background color    end;    // Adjust the height for the header row  Worksheet.WriteRowHeight(0, HEADER_FONT_SIZE * NICE_ROWHEIGHT_FACTOR, suPoints);    // Write data cells    for Row := 1 to StringGrid1.RowCount - 1 do    begin      for Col := 0 to StringGrid1.ColCount - 1 do      begin        // Check if cell contains a number        if TryStrToFloat(StringGrid1.Cells[Col, Row], TmpValue) then          Cell := Worksheet.WriteNumber(Row, Col, TmpValue)        else          Cell := Worksheet.WriteText(Row, Col, StringGrid1.Cells[Col, Row]);        // Add borders and center text      Worksheet.WriteBorders(Cell, [cbNorth, cbSouth, cbEast, cbWest]);        Worksheet.WriteHorAlignment(Cell, haCenter);        Worksheet.WriteVertAlignment(Cell, vaCenter);      end;    end;    // Adjust row heights based on content    for Row := 0 to Worksheet.GetLastRowIndex do      Worksheet.WriteRowHeight(Row, NICE_ROWHEIGHT_FACTOR * Worksheet.CalcAutoRowHeight(Row), Workbook.Units); [color=red]// --> !!!!  Set page layout: horizontally center the table[/color]  [b]  Worksheet.PageLayout.HorizontalCentered := True;[/b]     // Save the workbook as an XLSX file    Workbook.WriteToFile('WIEZEN.xlsx', sfOOXML, True);  finally    Workbook.Free;  end; ---------------------------------------------------------------------- dseligo · 2024-11-29 15:09 I think you have to do it for each cell (i.e. you can't do it for entire sheet). ---------------------------------------------------------------------- wp · 2024-11-29 15:15 What do you want to do? Centering a table in a pagelayout for printing? The correct way is this: 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   Worksheet.PageLayout.Options := Workseet.Pagelayout.Option + [poHorCentered]; ---------------------------------------------------------------------- seghele0 · 2024-11-30 11:01 Thanks "WP". Your code is error-free, but does not place the stringgrid horizontally in the center of the page (see attachment). Your code: 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 Worksheet.PageLayout.Options:= Worksheet.Pagelayout.Options + [poHorCentered];   Hopefully you can offer a solution. ---------------------------------------------------------------------- wp · 2024-11-30 16:44 Oh, this case among the many print options must have been forgotton in xlsx. Fixed in svn repository. Fixed also a bug in ods print page orientation ---------------------------------------------------------------------- seghele0 · 2024-12-01 12:19 WP, what exactly should I do now? Sotty, but your explanation isn't clear to me. Do I need to update the "fpSpreadsheet" component and where can I download it and what's the best way to update it in Lazarus. ---------------------------------------------------------------------- wp · 2024-12-01 12:49 Sorry. Yes, you must get yourself the latest version of the FPSpreadsheet library: I am assuming that you do not use svn. Therefore you should go to https://sourceforge.net/p/lazarus- ccr/svn/HEAD/tree/components/fpspreadsheet/ and download the "snapshot" from that page. Unzip it to some folder. Open the IDE and go to "Package" > "Load package file (.lpk)". Navigate to the folder to which you had unzipped the download, and select "laz_fpspreadsheet.lpk" > "Open". Click "Compile" (not absolutely necessary). If you use the visual spreadsheet components you must repeat this with "laz_fpspreadsheet_visual.lpk" and with "laz_fpspreadsheet_visual_dsgn.lpk". In case of the latter package you must also click "Use" > "Install" and confirm the prompt to rebuild the IDE. When the IDE has restarted after a while you will have the new fpspreadsheet. (You must repeat the same with "laz_fpspreadsheet_dataset.lpk" if you need to open spreadsheets as a database, and "laz_fpspreadsheetexport_visual.lpk" if you want to export database tables to spreadsheet files. And if you have encrypted Excel files you must also open the "laz_fpspreadsheet_crypto.lpk" package). ---------------------------------------------------------------------- seghele0 · 2024-12-01 15:30 "WP", real thanks. Your clear explanation is highly recommended for everyone. The StingGrid is now vertically in the center of the (printed) page. In the short future, there will be a few more questions to make the code of my program more readable and efficient.