unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
fpspreadsheetgrid;
type
{ TForm1 }
TForm1 = class(TForm)
Grid: TsWorksheetGrid;
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
variants, fpstypes;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
const
THICK_BORDER: TsCellBorderStyle = (LineStyle: lsThick; Color: scBlack);
var
r,c: Integer;
begin
// Turn off default grid lines
Grid.ShowGridLines := false;
// Turn off spreadsheet headers
//Grid.ShowHeaders := false;
// Cell block for "Sunday"
Grid.MergeCells(Rect(2,2, 2,8));
Grid.Cells[2,2] := 'Sunday';
Grid.CellFontSize[2,2] := 12;
Grid.CellFontStyle[2,2] := [fssBold];
Grid.CellFontColor[2,2] := scBlack;
Grid.TextRotation[2,2] := rt90DegreeCounterClockwiseRotation;
Grid.HorAlignment[2,2] := haCenter;
Grid.VertAlignment[2,2] := vaCenter;
// Cell block for date
Grid.MergeCells(Rect(3,2,3,8));
Grid.Cells[3,2] := DateToStr(EncodeDate(2016, 1, 17));
Grid.TextRotation[3,2] := rt90DegreeCounterClockwiseRotation;
Grid.HorAlignment[3,2] := haCenter;
Grid.VertAlignment[3,2] := vaCenter;
// cells 1,2,3,4
Grid.Cells[4,2] := 1;
Grid.CellFontStyle[4,2] := [fssBold];
Grid.HorAlignment[4,2] := haCenter;
Grid.VertAlignment[4,2] := vaCenter;
Grid.Cells[4,4] := 2;
Grid.CellFontStyle[4,4] := [fssBold];
Grid.HorAlignment[4,4] := haCenter;
Grid.VertAlignment[4,4] := vaCenter;
Grid.Cells[4,6] := 3;
Grid.CellFontStyle[4,6] := [fssBold];
Grid.HorAlignment[4,6] := haCenter;
Grid.VertAlignment[4,6] := vaCenter;
Grid.Cells[4,8] := 4;
Grid.CellFontStyle[4,8] := [fssBold];
Grid.HorAlignment[4,8] := haCenter;
Grid.VertAlignment[4,8] := vaCenter;
// other cells
for c := 5 to 16 do
begin
if not (c in [13, 16]) then
begin
Grid.Cells[c,2] := 'L1';
Grid.BackgroundColor[c,2] := $5BBA8A;
Grid.HorAlignment[c,2] := haCenter;
end;
if not (c in [10, 11, 15, 16]) then
begin
Grid.Cells[c,4] := 'L2';
Grid.BackgroundColor[c,4] := $4796F6;
Grid.HorAlignment[c,4] := haCenter;
end;
if not (c in [8, 9]) then
begin
Grid.Cells[c,6] := 'M1';
Grid.BackgroundColor[c,6] := $C5AB4B;
Grid.HorAlignment[c,6] := haCenter;
end;
if (c < 12) then
begin
Grid.Cells[c,6] := 'M1';
Grid.BackgroundColor[c,6] := $BC814F;
Grid.HorAlignment[c,6] := haCenter;
end;
if not (c in [7, 10..16]) then
begin
Grid.Cells[c,8] := 'M2';
Grid.BackgroundColor[c,8] := $FD6799;
Grid.HorAlignment[c,8] := haCenter;
end;
end;
// Column widths
for c := 1 to Grid.ColCount-1 do
Grid.ColWidths[c] := 40;
// Intermediate row heights
Grid.RowHeights[3] := 8;
Grid.RowHeights[5] := 8;
Grid.RowHeights[7] := 8;
// Border lines
for c:=2 to 16 do
begin
// top line
Grid.CellBorder[c, 2] := Grid.CellBorder[c, 2] + [cbNorth];
Grid.CellBorderStyle[c, 2, cbNorth] := THICK_BORDER;
// bottom line
Grid.CellBorder[c, 8] := Grid.CellBorder[c, 8] + [cbSouth];
Grid.CellBorderStyle[c, 8, cbSouth] := THICK_BORDER;
end;
// intermediate lines
for c:=4 to 16 do begin
Grid.CellBorder[c,2] := Grid.CellBorder[c,2] + [cbWest, cbSouth, cbNorth];
Grid.CellBorder[c,4] := Grid.CellBorder[c,4] + [cbWest, cbSouth, cbNorth];
Grid.CellBorder[c,6] := Grid.CellBorder[c,6] + [cbWest, cbSouth, cbNorth];
Grid.CellBorder[c,8] := Grid.CellBorder[c,8] + [cbWest, cbSouth, cbNorth];
end;
for r:=2 to 8 do begin
// Left line
Grid.CellBorder[2,r] := Grid.CellBorder[2,r] + [cbWest];
Grid.CellBorderStyle[2,r, cbWest] := THICK_BORDER;
// Right line
Grid.CellBorder[17,r] := [cbWest];
Grid.CellBorderStyle[17,r, cbWest] := THICK_BORDER;
// Right line of "Sunday", right line of date
Grid.CellBorder[3,r] := Grid.CellBorder[3,r] + [cbWest, cbEast];
Grid.CellBorderStyle[3,r, cbEast] := THICK_BORDER;
end;
end;
end.