procedure PrintWSGrid(aGrid: TsWorksheetGrid; aCanvas: TCanvas; aTitle: string);
var
X, X1, Y, w, h, t, aCol, aRow: integer;
s: string;
a: TsHorAlignment;
lCell: PCell;
fmt: PsCellFormat;
cbs: TsCellBorders;
fss: TsFontStyles;
fs: TFontStyles;
clr: TSColor;
sty: TFontStyles;
begin
t := 20;
with aCanvas do
begin
aCanvas.Pen.Color := clBlack;
aCanvas.Font.Name := AGrid.Font.Name;
aCanvas.Font.Size := 12;
aCanvas.Font.Style := [fsBold];
aCanvas.TextOut(50, 100, aTitle);
Y := AGrid.RowCount;
Y := 200;
h := 130;
aCanvas.Font.Size := 8;
aCanvas.Font.Style := [];
for aRow := 1 to AGrid.RowCount - 1 do
begin
x := 100;
y := y + h;
for aCol := 0 to aGrid.ColCount - 1 do
begin
lCell := aGrid.Worksheet.FindCell(ARow, ACol);
fmt := aGrid.Worksheet.GetPointerToEffectiveCellFormat(lCell);
w := Round(PrinterScaleX(aGrid.ColWidths[aCol + 1]));
s := aGrid.Worksheet.ReadAsText(aRow, aCol);
a := fmt^.HorAlignment;
if a = haCenter then
X1 := x + (w - PrinterScaleX(aGrid.Canvas.TextWidth(s))) div 2
else if a = haRight then
X1 := x + w - PrinterScaleX(aGrid.Canvas.TextWidth(s))
else
X1 := x;
clr := aGrid.CellFontColor[ACol + 1, ARow + 1];
aCanvas.Font.Color := clr;
fss := aGrid.CellFontStyle[ACol + 1, ARow + 1];
sty := [];
if fssBold in fss then
sty := sty + [fsBold];
if fssUnderline in fss then
sty := sty + [fsUnderline];
if fssItalic in fss then
sty := sty + [fsItalic];
aCanvas.Font.Style := sty;
aCanvas.TextOut(X1, y, s);
cbs := fmt^.Border;
if cbs <> [] then
begin
aCanvas.Brush.Color := clBlack;
if cbNorth in cbs then
aCanvas.FillRect(X, y, x + w, y + t);
if cbEast in cbs then
aCanvas.FillRect(X + w - t, y, x + w, y + h);
if cbSouth in cbs then
aCanvas.FillRect(X, y + h - t, x + w, y + h);
if cbWest in cbs then
aCanvas.FillRect(X, y, x + t, y + h);
fss := aGrid.CellFontStyles[acol, arow, acol + 1, arow + 1];
fs := aCanvas.Font.Style;
if fssBold in fss then
fs := [fsBold]
else
fs := [];
if fssUnderline in fss then
fs := fs + [fsUnderline];
aCanvas.Font.Style := fs;
aCanvas.Brush.Color := clWhite;
end;
X := X + w;
end;
end;
end;
end;