Recent

Author Topic: WriteBorderLineStyle(s) is missing [ANSWERED]  (Read 629 times)

totya

  • Hero Member
  • *****
  • Posts: 639
WriteBorderLineStyle(s) is missing [ANSWERED]
« on: July 15, 2020, 10:06:59 am »
Hi master!

I working my app hardly. These procedures:

Code: Pascal  [Select][+][-]
  1. function WriteBorderLineStyle(ARow, ACol: Cardinal; ABorder: TsCellBorder; ALineStyle: TsLineStyle): PCell; overload;
  2. procedure WriteBorderLineStyle(ACell: PCell; ABorder: TsCellBorder; ALineStyle: TsLineStyle): PCell; overload;

are okay...

But slightly complicated to draw to the corner, because two codeline needed, for example:

Code: Pascal  [Select][+][-]
  1.       if row_i = ARowStart then begin
  2.         WriteBorders(ARowStart, AColStart, [cbNorth, cbWest]);
  3.         WriteBorderLineStyle(ARowStart, AColStart, cbNorth, BorderLineStyle);
  4.         WriteBorderLineStyle(ARowStart, AColStart, cbWest, BorderLineStyle);
  5.       end
  6.  


...so I suggest these procedures too (similar to WriteBorders, WriteBorderStyles):

function WriteBorderLineStyles(ARow, ACol: Cardinal; ABorders: TsCellBorders; ALineStyle: TsLineStyle): PCell; overload;
procedure WriteBorderLineStyles(ACell: PCell; ABorders: TsCellBorders; ALineStyle: TsLineStyle): PCell; overload;

Thank you!
« Last Edit: July 27, 2020, 01:03:38 pm by totya »

wp

  • Hero Member
  • *****
  • Posts: 7636
Re: WriteBorderLineStyle(s) is missing
« Reply #1 on: July 15, 2020, 11:02:25 pm »
Since there are already so many methods of TsWorksheet I prefer to skip these.

But did you notice that recently I added methods to the TsCellFormat record (in order to facilitate working with conditional formats)?

Code: Pascal  [Select][+][-]
  1. type
  2.   TsCellFormat = record
  3.  ...
  4.     procedure SetBackground(AFillStyle: TsFillStyle; AFgColor, ABgColor: TsColor);
  5.     procedure SetBackgroundColor(AColor: TsColor);
  6.     procedure SetBorders(ABorders: TsCellBorders;
  7.       AColor: TsColor = scBlack; ALineStyle: TsLineStyle = lsThin);
  8.     procedure SetFont(AFontIndex: Integer);
  9.     procedure SetHorAlignment(AHorAlign: TsHorAlignment);
  10.     procedure SetTextRotation(ARotation: TsTextRotation);
  11.     procedure SetVertAlignment(AVertAlign: TsVertAlignment);
  12.   end;

Among them the SetBorders with the parameters of your request.

Code: Pascal  [Select][+][-]
  1. var
  2.   cell: PCell;
  3.   fmt: TsCellFormat;
  4. ...
  5.   cell := sheet.WriteNumber(2, 2, 3.141592);
  6.   fmt := book.GetCellFormat(cell^.FormatIndex);
  7.   fmt.SetBorders([cbNorth, cbWest], lsDouble, scRed);
  8.   cell^.FormatIndex := book.AddCellFormat(fmt);

Or, using the TCell helpers in fpsCell and the new CellFormat() function in fpsUtils, even faster:

Code: Pascal  [Select][+][-]
  1.     cell := sheet.WriteText(5, 2, 'abc');
  2.     cell^.Borders[[cbNorth, cbSouth]] := CellBorderStyle(lsThick, scGreen);
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

totya

  • Hero Member
  • *****
  • Posts: 639
Re: WriteBorderLineStyle(s) is missing
« Reply #2 on: July 16, 2020, 09:43:10 am »
Hi wp master!

Thank you for your detailed answer!

Quote
SetBorders

I read this information: https://wiki.freepascal.org/FPSpreadsheet#Cell_borders but I didn't found SetBorders. I searched in the fpspreadsheet-api.chm (shipped via component), but didn't found too. So this information is new for me. :)

Code: Pascal  [Select][+][-]
  1. Cell^.Borders

latest svn (7545): unit_tsworksheet_helper.pas(99,11) Error: identifier idents no member "Borders"

But the first solution is okay (modified, color and style parameter order is reverse):

Code: Pascal  [Select][+][-]
  1. begin // Top border...
  2.     for col_i := AColStart to AColEnd do
  3.     begin
  4.       Cell := GetCell(ARowStart, col_i);
  5.  
  6.       fmt := Workbook.GetCellFormat(Cell^.FormatIndex);
  7.       fmt.SetBorders([cbNorth], ABorderColor, ABorderLineStyle);
  8.       Cell^.FormatIndex := Workbook.AddCellFormat(fmt);
  9.     end;



wp

  • Hero Member
  • *****
  • Posts: 7636
Re: WriteBorderLineStyle(s) is missing
« Reply #3 on: July 16, 2020, 12:37:25 pm »
With every addition to fpspreadsheet, the documentation is getting more and more complex, and people are already complaining that the wiki article is too long and loads too slowly over the slow internet. An unsolvable situation...

I absolutely urge you (and everybody) to learn how to navigate the source code. It is always up to date, and I often add lots of comments to describe the functions (the comments are used by the chm help file generator). Please search the forum for "navigate" and my user name - I described the procedure already several times.

There is not yet any "official" documentation for the TCell record helpers. Here is the declaration of the methods:
Code: Pascal  [Select][+][-]
  1. type
  2.   TCellHelper = record helper for TCell
  3.   ...
  4.   public
  5.     property BackgroundColor: TsColor
  6.       read GetBackgroundColor write SetBackgroundColor;
  7.     property BiDiMode: TsBiDiMode
  8.       read GetBiDiMode write SetBiDiMode;
  9.     property Border: TsCellBorders
  10.       read GetBorder write SetBorder;
  11.     property Borders[ABorders: TsCellBorders]: TsCellBorderStyle
  12.       write SetBorders;  // write-only!
  13.     property BorderStyle[ABorder: TsCellBorder]: TsCellBorderStyle
  14.       read GetBorderStyle write SetBorderStyle;
  15.     property BorderStyles: TsCellBorderStyles
  16.       read GetBorderStyles write SetBorderStyles;
  17.     property CellFormat: TsCellFormat
  18.       read GetCellFormat write SetCellFormat;
  19.     property Comment: String
  20.       read GetComment write SetComment;
  21.     property Font: TsFont read GetFont;
  22.     property FontIndex: Integer
  23.       read GetFontIndex write SetFontIndex;
  24.     property HorAlignment: TsHorAlignment
  25.       read GetHorAlignment write SetHorAlignment;
  26.     property Hyperlink: TsHyperlink
  27.       read GetHyperlink write SetHyperlink;
  28.     property NumberFormat: TsNumberFormat
  29.       read GetNumberFormat write SetNumberFormat;
  30.     property NumberFormatStr: String
  31.       read GetNumberFormatStr write SetNumberFormatStr;
  32.     property TextRotation: TsTextRotation
  33.       read GetTextRotation write SetTextRotation;
  34.     property UsedFormattingFields: TsUsedFormattingFields
  35.       read GetUsedFormattingFields write SetUsedFormattingFields;
  36.     property VertAlignment: TsVertAlignment
  37.       read GetVertAlignment write SetVertAlignment;
  38.     property Wordwrap: Boolean
  39.       read GetWordwrap write SetWordwrap;
  40.     property Workbook: TsBasicWorkbook read GetWorkbook;
  41.   end;

Having unit fpscell in "uses" you can simply set these properties:
Code: Pascal  [Select][+][-]
  1. var
  2.   cell: PCell;
  3. ...
  4.   cell := worksheet.WriteNumber(1, 2, 3.141592);
  5.   cell^.NumberFormatStr := '0.00';
  6.   cell^.BackgroundColor := scRed;
  7.   cell^.Borders[[cbNorth, cbSourh]] := CellBorderStyle(scRed, scDouble);

A special note should be make for the property Borders (plural) which is write-only. In the above example, the top and bottem borders of the cell are set as red double lines. (Using the color scUndefined or scTransparent as color parameter hides the border line). It does not make sense to read back the cell border styles because the border elements specified in the parameter may be different.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

totya

  • Hero Member
  • *****
  • Posts: 639
Re: WriteBorderLineStyle(s) is missing
« Reply #4 on: July 18, 2020, 03:54:54 pm »
Hi wp master!

Thank you for this information. The wiki page is very detailed, and I didn't tought before, this is incomplete. I suggest to you write to the top of the wiki page this informations with big letters (about): These informations outdated, please see source code...


wp

  • Hero Member
  • *****
  • Posts: 7636
Re: WriteBorderLineStyle(s) is missing
« Reply #5 on: July 18, 2020, 04:21:50 pm »
These informations outdated, please see source code...
No it's not outdated, it just does not explain each of the many ways of formatting. I'll probably write a new, more complete article about formatting; when it is not included in the main article I think there is more space to explain more details.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

totya

  • Hero Member
  • *****
  • Posts: 639
Re: WriteBorderLineStyle(s) is missing
« Reply #6 on: July 20, 2020, 01:28:21 pm »
Hi master!

For example this line in the wiki is outdated:

Code: Pascal  [Select][+][-]
  1. fnt := MyWorksheet.ReadCellFont(0, 0);

...because the required paramters: PCell and not row/col.

wp

  • Hero Member
  • *****
  • Posts: 7636
Re: WriteBorderLineStyle(s) is missing
« Reply #7 on: July 20, 2020, 11:58:35 pm »
Thanks for reporting. Fixed.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018