fpspreadsheet: Facilitate using cell borders and cell border styles.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7544 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-07-15 21:03:54 +00:00
parent 001fc5ecce
commit a3e2c6c8a3
4 changed files with 49 additions and 25 deletions

View File

@@ -31,6 +31,7 @@ type
procedure SetBackgroundColor(const AValue: TsColor);
procedure SetBiDiMode(const AValue: TsBiDiMode);
procedure SetBorder(const AValue: TsCellBorders);
procedure SetBorders(const ABorders: TsCellBorders; const AValue: TsCellBorderStyle);
procedure SetBorderStyle(const ABorder: TsCellBorder; const AValue: TsCellBorderStyle);
procedure SetBorderStyles(const AValue: TsCellBorderStyles);
procedure SetCellFormat(const AValue: TsCellFormat);
@@ -55,6 +56,8 @@ type
read GetBiDiMode write SetBiDiMode;
property Border: TsCellBorders
read GetBorder write SetBorder;
property Borders[ABorders: TsCellBorders]: TsCellBorderStyle
write SetBorders; // write-only!
property BorderStyle[ABorder: TsCellBorder]: TsCellBorderStyle
read GetBorderStyle write SetBorderStyle;
property BorderStyles: TsCellBorderStyles
@@ -204,6 +207,16 @@ begin
(Worksheet as TsWorksheet).WriteBorders(@self, AValue);
end;
procedure TCellHelper.SetBorders(const ABorders: TsCellBorders;
const AValue: TsCellBorderStyle);
var
fmt: TsCellFormat;
begin
fmt := CellFormat;
fmt.SetBorders(ABorders, AValue.Color, AValue.LineStyle);
CellFormat := fmt;
end;
procedure TCellHelper.SetBorderStyle(const ABorder: TsCellBorder;
const AValue: TsCellBorderStyle);
begin

View File

@@ -543,6 +543,8 @@ const
{@@ Border style to be used for "no border"}
NO_CELL_BORDER: TsCellBorderStyle = (LineStyle: lsThin; Color: scNotDefined);
ALL_BORDERS: TsCellBorders = [cbNorth, cbEast, cbSouth, cbWest];
type
{@@ Style of fill pattern for cell backgrounds }
TsFillStyle = (fsNoFill, fsSolidFill,
@@ -724,7 +726,7 @@ type
procedure SetBackground(AFillStyle: TsFillStyle; AFgColor, ABgColor: TsColor);
procedure SetBackgroundColor(AColor: TsColor);
procedure SetBorders(ABorders: TsCellBorders;
AColor: TsColor = scBlack; ALineStyle: TsLineStyle = lsThin);
const AColor: TsColor = scBlack; const ALineStyle: TsLineStyle = lsThin);
procedure SetFont(AFontIndex: Integer);
procedure SetHorAlignment(AHorAlign: TsHorAlignment);
procedure SetTextRotation(ARotation: TsTextRotation);
@@ -1088,13 +1090,13 @@ begin
end;
procedure TsCellFormat.SetBorders(ABorders: TsCellBorders;
AColor: TsColor = scBlack; ALineStyle: TsLineStyle = lsThin);
const AColor: TsColor = scBlack; const ALineStyle: TsLineStyle = lsThin);
var
cb: TsCellBorder;
begin
for cb in ABorders do
begin
if (AColor = scTransparent) then
if (AColor = scTransparent) or (AColor = scNotDefined) then
Exclude(Border, cb)
else
begin

View File

@@ -227,7 +227,11 @@ function SameFont(AFont1, AFont2: TsFont): Boolean; overload;
function SameFont(AFont: TsFont; AFontName: String; AFontSize: Single;
AStyle: TsFontStyles; AColor: TsColor; APos: TsFontPosition): Boolean; overload;
function Range(ARow1, ACol1, ARow2, ACol2: Cardinal): TsCellRange;
function Range(ARow, ACol: Cardinal): TsCellRange; overload;
function Range(ARow1, ACol1, ARow2, ACol2: Cardinal): TsCellRange; overload;
function CellBorderStyle(const AColor: TsColor = scBlack;
const ALineStyle: TsLineStyle = lsThin): TsCellBorderStyle;
function GetFontAsString(AFont: TsFont): String;
@@ -2757,9 +2761,20 @@ begin
(AFont.Position = APos);
end;
{@@ ----------------------------------------------------------------------------
Creates a TsCellRange record from the coordinates of a single cell.
-------------------------------------------------------------------------------}
function Range(ARow, ACol: Cardinal): TsCellRange;
begin
Result.Row1 := ARow;
Result.Row2 := ARow;
Result.Col1 := ACol;
Result.Col2 := ACol;
end;
{@@ ----------------------------------------------------------------------------
Creates a TsCellRange record from the provided cell corner coordinates.
Put the coordinates into right order if needed.
Puts the coordinates into right order if needed.
-------------------------------------------------------------------------------}
function Range(ARow1, ACol1, ARow2, ACol2: Cardinal): TsCellRange;
begin
@@ -2803,31 +2818,16 @@ begin
end;
end;
(*
{@@ ----------------------------------------------------------------------------
Constructs a string of length "Len" containing random uppercase characters
Combines color and linestyle to a TsCellBorderStyle record
-------------------------------------------------------------------------------}
function GetRandomString(Len: Integer): String;
function CellBorderStyle(const AColor: TsColor = scBlack;
const ALineStyle: TsLineStyle = lsThin): TsCellBorderStyle;
begin
Result := '';
While Length(Result) < Len do
Result := Result + char(ord('A') + random(26));
Result.Color := AColor;
Result.LineStyle := ALineStyle;
end;
{@@ ----------------------------------------------------------------------------
Constructs a unique folder name in the temp directory of the OS
-------------------------------------------------------------------------------}
function GetUniqueTempDir(Global: Boolean): String;
var
tempdir: String;
begin
tempdir := AppendPathDelim(GetTempDir(Global));
repeat
Result := tempdir + AppendPathDelim(GetRandomString(8));
until not DirectoryExists(Result);
end;
*)
{@@ ----------------------------------------------------------------------------
Appends a string to a stream