Forum > Beginners
Worksheet.PageLayout
seghele0:
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 [+][-]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 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:
I think you have to do it for each cell (i.e. you can't do it for entire sheet).
wp:
What do you want to do? Centering a table in a pagelayout for printing?
The correct way is this:
--- 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";}};} --- Worksheet.PageLayout.Options := Workseet.Pagelayout.Option + [poHorCentered];
seghele0:
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 [+][-]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";}};} ---Worksheet.PageLayout.Options:= Worksheet.Pagelayout.Options + [poHorCentered]; Hopefully you can offer a solution.
;)
wp:
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
Navigation
[0] Message Index
[#] Next page