Documents

NextGrid & NextDBGrid

NextGrid

NextDBGrid

NextInspector

NextSheet

NextCollection

Misc

Labs

NextGrid .NET

Formating in NextSheet

Related Articles:

Info
  • Skill:
  • Version: 1.0.3
  • Author: Bojan Nikolic
  • Created:
  • Updated: 2009-07-30
This article require NextSheet 1.0.0

1. Introducing



Cell inside NextSheet may be formated in warious ways. There many elements to format such as cell's color, 4 borders, font, cell's kind, format mask...

1.1. Formating single cells



Cell may be formated alone at the time where Cell[] property is used. Example:

Cell[2, 3].Color := clRed;
Cell[2, 3].Font.Size := 12;


or with using with command from Delphi:

with Cell[2, 3] do
begin
  Color := clRed;
  Font.Size := 12;
end;


Cell[2][3]->Color = clRed;
Cell[2][3]->Font->Size = 12;


2. Cell Kind



Kind property is one of most important Cell's properties.

Table 1: TCellKind
Name Meaning
ckGeneral No formatting rules to be used.
ckNumber Number formatting rules may be applied to cell's text with FormatMask.
ckDateTime Date/Time formatting rules may be applied to cell's text with FormatMask.


Example:

NextSheet1.Cell[1, 2].Text := DateToStr(Today);
NextSheet1.Cell[1, 2].Kind := ckDateTime;
NextSheet1.Cell[1, 2].FormatMask := 'mmm yyyy';


3. Cell borders



As mentioned in previous article, each cell include 4 properties for border: BorderLeft, BorderTop, BorderBottom, BorderRight. This borders are shared between 2 "neighbor" cells so setting bottom border will set border of cell bellow.

Border have 3 properties: Color which specify border's color, Position which is read-only property and determine border's position with cell, and LineStyle which represents style of border:

Table 2: Border LineStyleS
Name Preview
lsNone
lsThinDot
lsDot
lsDashDotDot not supported
lsWideDot
lsThinLine
lsWeightDashDotDot
lsSkewDashDot not supported
lsWeightDashDot not supported
lsWeightDash not supported
lsSolid
lsWightSolid
lsDouble


Example:

// Draw multi-color border cell and color it in clCream
with NextSheet1.Cell[1, 1] do
begin
  BorderTop.LineStyle := lsThinDot;
  BorderTop.Color := clPurple;

  BorderLeft.LineStyle := lsDouble;
  BorderLeft.Color := clRed;

  BorderBottom.LineStyle := lsWeightDashDotDot;
  BorderBottom.Color := clNavy;

  Color := clCream;
end;


Result:



4. StylePainter object



As mentioned in first article about NextSheet StylePainter is handy object property which may be usefull for applying desired style (Alignment, Color, Font...). All needed is to set this sub-properties of StylePainter and call Apply method to apply this "styles" to range of cells.

This method is in next format:

procedure Apply(FromCol, FromRow, ToCol, ToRow: Integer);


In 1.0.7 Beta there is a new Paint method for individial cells.

5. FormatMask property



Each cell include FormatMask property, but how this format mask will be applied to the cell's value depends from Kind property of cell.

uses NxSheetCell, DateUtils;
...
NextSheet1.Cell[0, 0].Value := '12345.00';
NextSheet1.Cell[0, 0].Kind := ckNumber;
NextSheet1.Cell[0, 0].FormatMask := '#,##0.00';

NextSheet1.Cell[0, 1].Value := DateToStr(Today);
NextSheet1.Cell[0, 1].Kind := ckDateTime;
NextSheet1.Cell[0, 1].FormatMask := 'd.m.yyyy';


Result:



For formating ckNumber kind of cells, FormatFloat standard Delphi function is used. More details in Delphi help.
For formating ckDateTime kind of cells, FormatDateTime standard Delphi function is used. More details in Delphi help.

6. Clear formating



To clear formating of cell, you may simply set their properties back to default values or use ClearFormating function on range of cells.

// Clear cell colors and borders of all cells
NextSheet1.ClearFormating(0, 0, NextSheet1.ColCount - 1, NextSheet1.RowCount - 1);


7. Procedures and functions



FrameCell procedure draw's frame (set Color and LineStyle properties is parameters) around cell. Example:

Example:

NextSheet1.FrameCell(NextSheet1.SelectedCol, NextSheet1.SelectedRow, lsSolid, clBlue);


Erase - Clear Text property for range of cells.

Example:

NextShee1.Erase(2, 2, 4, 3);


NextShee1->Erase(2, 2, 4, 3);


AssignCell1.3.5

Assign Text and formatting from source cell.

Example:

NextSheet.AssignCell(3, 3, 4, 4);

Was This Article Useful?

Only constructive comments, code contributions... will be publishes. Questions, non-official discussion will not be published.