SharpCell.Grid

GridPainter

public sealed class GridPainter

Namespace SharpCell.Grid · package SharpCell.Grid

Paints a worksheet the way Excel shows it: column and row headers, gridlines, each cell's Cell.Text in its style (font, fill, borders, alignment, wrapping, indent), merged areas as one cell, and the active cell. Only the cells inside the viewport are read, so a sheet's size does not matter. Also answers the geometry questions of a grid on screen: where a cell is, what is under a point, where to scroll. With GridPainter.MeasureText set, text too wide for its cell runs on over empty neighbours, numbers too wide for their column are shortened or shown as ###, and row headers widen for long row numbers, as in Excel.

Constructors

GridPainter()

public GridPainter()

A painter with Excel's default row heights and column widths.

GridPainter(SheetLayout)

public GridPainter(SheetLayout layout)

A painter over the given sizes of rows and columns.

Properties

ColumnHeaderHeight

public double ColumnHeaderHeight { get; set; }

The height of the column headers at the top at 100% zoom; GridPainter.Zoom scales it.

CopiedArea

public CellArea? CopiedArea { get; set; }

The cells copied or cut, painted with a dashed border as Excel shows them until they are pasted; null for none.

FillArea

public CellArea? FillArea { get; set; }

The cells a fill handle is being dragged over, painted with a dashed grey border; null for none.

FrozenColumns

public int FrozenColumns { get; set; }

How many columns on the left stay in place while the rest scrolls; a sheet's own is Worksheet.FrozenColumns.

Exceptions

FrozenRows

public int FrozenRows { get; set; }

How many rows at the top stay in place while the rest scrolls, as Excel's Freeze Panes; a sheet's own is Worksheet.FrozenRows.

Exceptions

Layout

public SheetLayout Layout { get; set; }

The sizes of rows and columns; SheetLayout.FromWorksheet gives a sheet's own.

MeasureText

public Func<string, GridFont, double>? MeasureText { get; set; }

The width in pixels of a line of text in a font. Without it, text is never fitted to its cell, row headers keep GridPainter.RowHeaderWidth, and Calibri 11's digit width is assumed.

ReferenceArea

public CellArea? ReferenceArea { get; set; }

The cells picked with the mouse while a formula is typed, painted with a dashed blue border; null for none.

RowHeaderWidth

public double RowHeaderWidth { get; set; }

The width of the row headers on the left at 100% zoom; with GridPainter.MeasureText, the least width, widened to fit the number of the last visible row. GridPainter.Zoom scales it.

ShowsFillHandle

public bool ShowsFillHandle { get; set; }

Whether the selection's bottom-right corner has Excel's fill handle, the square dragged to fill cells. False by default; a view that changes cells turns it on.

Theme

public GridTheme Theme { get; set; }

The colours of everything but the cells' own styles.

Zoom

public double Zoom { get; set; }

How large cells and headers are painted, 1 for Excel's 100%: fonts, headers and the space around text grow with it, lines stay one pixel. GridPainter.Layout is not scaled: give it the sheet's sizes at the zoom, as SheetLayout.FromWorksheet with GridPainter.MaxDigitWidth does.

Exceptions

Methods

CellBounds(GridViewport, CellPosition)

public GridRect CellBounds(GridViewport viewport, CellPosition cell)

Where a cell is on screen; it may lie outside the viewport.

CellBounds(GridViewport, CellPosition, CellPosition)

public GridRect CellBounds(GridViewport viewport, CellPosition first, CellPosition last)

Where a rectangle of cells is on screen, from its top-left to its bottom-right cell.

CellNearest(GridViewport, double, double)

public CellPosition CellNearest(GridViewport viewport, double x, double y)

The cell nearest to a point, for dragging a selection: the cell under it, or past an edge of the cells the next one out of view that way, so that scrolling to it follows the mouse.

Clamp(GridViewport)

public GridViewport Clamp(GridViewport viewport)

The viewport with its offsets kept between the start and the end of the sheet.

ColumnEdgeAt(GridViewport, double, double)

public int? ColumnEdgeAt(GridViewport viewport, double x, double y)

The column whose right edge is under a point of the column headers, as Excel lets it be dragged to resize the column; null elsewhere. Hidden columns are never found.

FitColumnWidth(Worksheet, int)

public double? FitColumnWidth(Worksheet sheet, int column)

The width in pixels at GridPainter.Zoom that fits the widest text of a column, as Excel's AutoFit Column Width does; merged cells are left out. Null when the column holds nothing to fit or without GridPainter.MeasureText.

FitRowHeight(Worksheet, int)

public double? FitRowHeight(Worksheet sheet, int row)

The height in pixels at GridPainter.Zoom that fits the tallest text of a row, as Excel's AutoFit Row Height does: a line of each cell's font, and as many lines as wrapped text or line breaks take. Null when the row holds nothing, for the sheet's default height.

FontOf(CellFont)

public static GridFont FontOf(CellFont font)

The font of a SharpCell font at 96 DPI.

Hit(GridViewport, double, double, Worksheet)

public GridHit? Hit(GridViewport viewport, double x, double y, Worksheet? sheet = null)

What is under a point of the grid: a cell, a column or row header, or the corner above the row headers; null outside the grid. GridSelection.At turns it into what a click selects.

HitTest(GridViewport, double, double, Worksheet)

public CellPosition? HitTest(GridViewport viewport, double x, double y, Worksheet? sheet = null)

The cell under a point of the grid; null on the headers or outside the grid. Inside a merged area of the sheet, its top-left cell.

IsOnFillHandle(GridViewport, double, double, GridSelection, Worksheet)

public bool IsOnFillHandle(GridViewport viewport, double x, double y, GridSelection? selection, Worksheet? sheet)

Whether a point is on the fill handle of the selection, when GridPainter.ShowsFillHandle shows one.

MaxDigitWidth(Worksheet)

public double MaxDigitWidth(Worksheet? sheet)

The width in pixels of the widest digit of a sheet's default font at GridPainter.Zoom, which Excel bases column widths on; 7, Calibri 11's at 100%, without GridPainter.MeasureText.

Paint(IGridCanvas, Worksheet, GridViewport, CellPosition?)

public void Paint(IGridCanvas canvas, Worksheet? sheet, GridViewport viewport, CellPosition? activeCell = default)

Paints the part of the sheet in the viewport with the active cell alone selected; without a sheet, an empty grid.

Paint(IGridCanvas, Worksheet, GridViewport, GridSelection)

public void Paint(IGridCanvas canvas, Worksheet? sheet, GridViewport viewport, GridSelection? selection)

Paints the part of the sheet in the viewport and the selection over it, as Excel does: the selected cells but the active one shaded, a border around them, their headers highlighted. Without a sheet, an empty grid; without a selection, none.

RowEdgeAt(GridViewport, double, double)

public int? RowEdgeAt(GridViewport viewport, double x, double y)

The row whose bottom edge is under a point of the row headers; null elsewhere. See GridPainter.ColumnEdgeAt.

ScrollIntoView(GridViewport, CellPosition)

public GridViewport ScrollIntoView(GridViewport viewport, CellPosition cell)

The viewport scrolled just enough to show the whole cell, or its top-left part when it is larger than the viewport; unchanged when the cell is already in view.

VisibleArea(GridViewport)

public CellArea VisibleArea(GridViewport viewport)

The cells the viewport shows, partly or wholly, of the part that scrolls: frozen rows and columns aside.