Recent

Author Topic: PageLayout  (Read 3045 times)

jcmontherock

  • Full Member
  • ***
  • Posts: 234
PageLayout
« on: March 23, 2018, 11:05:10 am »
Hello, could you show me how we could use: Worksheet.PageLayout.RepeatedRows ?
Thanks in advance.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: PageLayout
« Reply #1 on: March 23, 2018, 01:03:41 pm »
cited from http://wiki.lazarus.freepascal.org/FPSpreadsheet#Page_layout:
Quote
Header rows and columns repeated on every printed page can be defined by the RepeatedCols and RepeatedRows records; their elements FirstIndex and LastIndex refer to the indexes of the first and last column or row, respectively, to be repeated. Use the methods SetRepeatedCols and SetRepeatedRows to define these numbers. Note that the second parameter for the last index can be omitted to use only a single header row or column.

Here is a sample project which deminstrates the application of repeated rows and columns:
Code: Pascal  [Select][+][-]
  1. program demo_pagelayout;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   math,
  7.   fpstypes, fpspreadsheet, xlsxooxml;
  8.  
  9. var
  10.   book: TsWorkbook;
  11.   sheet: TsWorksheet;
  12.   row, col: Cardinal;
  13.   x: Double;
  14.  
  15. const
  16.   XMIN = -10;
  17.   XMAX = 10;
  18.   N = 100;
  19.  
  20. begin
  21.   book := TsWorkbook.Create;
  22.   try
  23.     sheet := book.AddWorksheet('Sheet1');
  24.  
  25.     sheet.WriteText(0, 0, 'Index');
  26.     sheet.WriteHorAlignment(0, 0, haRight);
  27.     sheet.WriteText(0, 1, 'x');
  28.     sheet.WriteHorAlignment(0, 1, haRight);
  29.     sheet.WriteText(0, 2, 'y=sin(x)');
  30.     sheet.WriteHorAlignment(0, 2, haRight);
  31.     sheet.WriteText(0, 3, 'y=cos(x)');
  32.     sheet.WriteHorAlignment(0, 3, haRight);
  33.     sheet.WriteText(0, 4, 'y=sin(x)^2');
  34.     sheet.WriteHorAlignment(0, 4, haRight);
  35.     sheet.WriteText(0, 5, 'y=cos(x)^2');
  36.     sheet.WriteHorAlignment(0, 5, haRight);
  37.     sheet.WriteText(0, 6, 'y=sin(x)^3');
  38.     sheet.WriteHorAlignment(0, 6, haRight);
  39.     sheet.WriteText(0, 7, 'y=cos(x)^3');
  40.     sheet.WriteHorAlignment(0, 7, haRight);
  41.  
  42.     for row := 1 to N do begin
  43.       x := (row - 1) / N * (XMAX - XMIN) + XMIN;
  44.       sheet.writeNumber(row, 0, row);
  45.       sheet.WriteNumber(row, 1, x, nfFixed, 5);
  46.       sheet.WriteNumber(row, 2, sin(x), nfFixed, 5);
  47.       sheet.WriteNumber(row, 3, cos(x), nfFixed, 5);
  48.       sheet.WriteNumber(row, 4, sin(x)**2, nfFixed, 5);
  49.       sheet.WriteNumber(row, 5, cos(x)**2, nfFixed, 5);
  50.       sheet.WriteNumber(row, 6, sin(x)**3, nfFixed, 5);
  51.       sheet.WriteNumber(row, 7, cos(x)**3, nfFixed, 5);
  52.     end;
  53.  
  54.     for col := 1 to 7 do
  55.       sheet.WriteBorders(0, col, [cbSouth]);
  56.     for row :=1 to N do
  57.       sheet.WriteBorders(row, 0, [cbEast]);
  58.     sheet.WriteBorders(0, 0, [cbEast, cbSouth]);
  59.  
  60.  
  61.     // Rows 0 will be repeated
  62.     sheet.PageLayout.SetRepeatedRows(0, 0);
  63.  
  64.     // Col 0 will be repeated
  65.     sheet.PageLayout.SetRepeatedCols(0, 0);
  66.  
  67.     book.WriteToFile('pagelayout.xlsx', true);
  68.   finally
  69.     book.Free;
  70.   end;
  71. end.

jcmontherock

  • Full Member
  • ***
  • Posts: 234
Re: PageLayout
« Reply #2 on: March 23, 2018, 05:16:44 pm »
Thank you. It works fine.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

 

TinyPortal © 2005-2018