SheetLayout
public sealed class SheetLayout
Namespace SharpCell.Grid · package SharpCell.Grid
Where the cells of a sheet are, in device-independent pixels from the top-left corner of cell A1: column widths, row heights, their offsets, the cell under a point and the cells inside a viewport. Covers Excel's whole sheet, 1,048,576 rows by 16,384 columns. Rows and columns are numbered from 1.
Constructors
SheetLayout()
public SheetLayout()
A layout with Excel's default sizes.
SheetLayout(double, double)
public SheetLayout(double defaultColumnWidth, double defaultRowHeight)
A layout with the given default sizes, in pixels.
Exceptions
ArgumentOutOfRangeException: A size is not positive.
Properties
DefaultColumnWidth
public double DefaultColumnWidth { get; set; }
The width of every column without a width of its own.
Exceptions
ArgumentOutOfRangeException: The width is not positive.
DefaultRowHeight
public double DefaultRowHeight { get; set; }
The height of every row without a height of its own.
Exceptions
ArgumentOutOfRangeException: The height is not positive.
Height
public double Height { get; }
The height of all rows together.
Width
public double Width { get; }
The width of all columns together.
Methods
ColumnAt(double)
public int ColumnAt(double x)
The column under a horizontal offset, clamped to the sheet; hidden columns are never hit.
ColumnLeft(int)
public double ColumnLeft(int column)
The offset of a column's left edge; 0 for column A.
Exceptions
ArgumentOutOfRangeException: The column is outside the sheet.
ColumnWidth(int)
public double ColumnWidth(int column)
The width of a column.
Exceptions
ArgumentOutOfRangeException: The column is outside the sheet.
ColumnWidthFromPixels(double, double)
public static double ColumnWidthFromPixels(double pixels, double maxDigitWidth)
The column width, in the units of Worksheet.SetColumnWidth, that Excel gives a column dragged to a width in pixels: Truncate((c * d + 5) / d * 256) / 256 for c = Truncate((pixels - 5) / d * 100 + 0.5) / 100 characters, as Excel shows it while dragging. Narrower than a digit and its padding, the smallest width that shows the pixels.
Parameters
pixels: The width in pixels.maxDigitWidth: The width in pixels of the widest digit of the default font, at the zoom the pixels are at.
Exceptions
ArgumentOutOfRangeException: The digit width is not positive, or the pixels are negative.
FromWorksheet(Worksheet, double)
public static SheetLayout FromWorksheet(Worksheet sheet, double maxDigitWidth)
A layout with a worksheet's column widths, row heights and hidden rows and columns, in pixels at 100% zoom as Excel converts them: a width of w characters is Truncate((256 * w + Truncate(128 / d)) / 256 * d) pixels, d being the width of the widest digit of the workbook's default font (7 for Calibri 11); a height of h points is h * 96 / 72 pixels, rounded. Later changes to the sheet are not followed.
Parameters
sheet: The sheet.maxDigitWidth: The width in pixels of the widest digit of the default font.
Exceptions
ArgumentOutOfRangeException: The digit width is not positive.
FromWorksheet(Worksheet, double, double)
public static SheetLayout FromWorksheet(Worksheet sheet, double maxDigitWidth, double zoom)
A layout with a worksheet's sizes at a zoom, as Excel shows them: column widths from the digit width of the default font at that zoom, row heights in points times the zoom.
Parameters
sheet: The sheet.maxDigitWidth: The width in pixels of the widest digit of the default font at the zoom.zoom: The zoom, 1 for 100%.
Exceptions
ArgumentOutOfRangeException: The digit width or the zoom is not positive.
RowAt(double)
public int RowAt(double y)
The row under a vertical offset, clamped to the sheet; hidden rows are never hit.
RowHeight(int)
public double RowHeight(int row)
The height of a row.
Exceptions
ArgumentOutOfRangeException: The row is outside the sheet.
RowHeightFromPixels(double, double)
public static double RowHeightFromPixels(double pixels, double zoom)
The row height in points, as Excel stores it, of a row shown that many pixels high at a zoom.
Parameters
pixels: The height in pixels.zoom: The zoom the pixels are at, 1 for 100%.
Exceptions
ArgumentOutOfRangeException: The zoom is not positive, or the pixels are negative.
RowTop(int)
public double RowTop(int row)
The offset of a row's top edge; 0 for row 1.
Exceptions
ArgumentOutOfRangeException: The row is outside the sheet.
SetColumnWidth(int, double)
public void SetColumnWidth(int column, double width)
Gives a column a width; zero hides it, the default width forgets the change.
Exceptions
ArgumentOutOfRangeException: The column is outside the sheet, or the width is negative.
SetRowHeight(int, double)
public void SetRowHeight(int row, double height)
Gives a row a height; zero hides it, the default height forgets the change.
Exceptions
ArgumentOutOfRangeException: The row is outside the sheet, or the height is negative.
VisibleArea(double, double, double, double)
public CellArea VisibleArea(double x, double y, double width, double height)
The cells that a rectangle of the sheet touches, partly or wholly.
Exceptions
ArgumentOutOfRangeException: The width or height is negative.