<!-- Generated by tools/SharpCell.Grid.Docs from the XML documentation comments. Do not edit; run the tool with 'generate'. -->

# SpreadsheetView

```csharp
public class SpreadsheetView : FrameworkElement
```

Namespace `SharpCell.Grid.Wpf` · package `SharpCell.Grid.Wpf`

Shows a SharpCell worksheet as Excel does: headers, gridlines, each cell's text as Excel formats it in the cell's style, the sheet's column widths, row heights, merged cells, frozen panes and gridlines. Cells are selected as in Excel: by clicking and dragging, by Shift with a click or the arrows, whole columns and rows from their headers or with Ctrl+Space and Shift+Space, the whole sheet from the corner or with Ctrl+A. Enter and Tab move inside a selection, the wheel scrolls and with Ctrl zooms, and Ctrl+C puts the selected cells on the clipboard as Excel pastes them. Columns and rows are resized by dragging the edges of their headers, and fitted by double-clicking them; the fill handle fills cells, and the headers have Excel's menu to insert, delete and hide them. Only the visible cells are read, so any sheet size works. The view reads cells when it paints; after changing cells or recalculating, call `UIElement.InvalidateVisual`. Sizes and frozen panes are taken when [SpreadsheetView.Worksheet](SharpCell.Grid.Wpf.SpreadsheetView.md#worksheet) is set; after changing them, call [SpreadsheetView.ReloadLayout](SharpCell.Grid.Wpf.SpreadsheetView.md#reloadlayout).

## Constructors

<a id="ctor"></a>
### SpreadsheetView()

```csharp
public SpreadsheetView()
```

Creates an empty view; set [SpreadsheetView.Worksheet](SharpCell.Grid.Wpf.SpreadsheetView.md#worksheet) to show a sheet.

## Properties

<a id="activecell"></a>
### ActiveCell

```csharp
public CellPosition? ActiveCell { get; set; }
```

The cell with the active-cell border; null shows none. It is the active cell of [SpreadsheetView.Selection](SharpCell.Grid.Wpf.SpreadsheetView.md#selection); setting it selects that cell alone.

<a id="edittext"></a>
### EditText

```csharp
public string? EditText { get; set; }
```

The text being typed into the active cell, which [SpreadsheetView.CommitEdit](SharpCell.Grid.Wpf.SpreadsheetView.md#commitedit) enters; null when no cell is being edited. Setting it while editing changes the text, as a formula bar does.

<a id="editor"></a>
### Editor

```csharp
public GridEditor? Editor { get; }
```

What changes the cells, with the history to undo and redo; one per workbook, created when [SpreadsheetView.Worksheet](SharpCell.Grid.Wpf.SpreadsheetView.md#worksheet) is set. Null without a sheet.

<a id="isediting"></a>
### IsEditing

```csharp
public bool IsEditing { get; }
```

Whether a cell is being edited.

<a id="isreadonly"></a>
### IsReadOnly

```csharp
public bool IsReadOnly { get; set; }
```

Whether cells cannot be changed: no typing, Delete, pasting, undo or redo.

<a id="offset"></a>
### Offset

```csharp
public Vector Offset { get; set; }
```

How far the cells are scrolled, in pixels from cell A1; kept inside the sheet when painting.

<a id="painter"></a>
### Painter

```csharp
public GridPainter Painter { get; }
```

Geometry and colours: row heights, column widths, header sizes, theme.

<a id="selection"></a>
### Selection

```csharp
public GridSelection? Selection { get; set; }
```

The selected cells, the active cell among them; null selects none. A new sheet starts from its active cell alone.

<a id="viewport"></a>
### Viewport

```csharp
public GridViewport Viewport { get; }
```

What the view shows now: its size and its offset, kept inside the sheet.

<a id="worksheet"></a>
### Worksheet

```csharp
public Worksheet? Worksheet { get; set; }
```

The sheet shown; null shows an empty grid.

<a id="zoom"></a>
### Zoom

```csharp
public double Zoom { get; set; }
```

How large the cells are shown, 1 for Excel's 100%, from 0.1 to 4; Ctrl with the wheel changes it in steps of 10%. The cell at the top left stays there.

## Methods

<a id="beginedit-string"></a>
### BeginEdit(string)

```csharp
public bool BeginEdit(string? text = null)
```

Starts editing the active cell, as F2 does: with its formula or value as Excel shows it to edit, or with `text`. False when the view is read-only or has no sheet.

<a id="canceledit"></a>
### CancelEdit()

```csharp
public void CancelEdit()
```

Ends editing without changing the cell, as Escape does.

<a id="clearselection"></a>
### ClearSelection()

```csharp
public void ClearSelection()
```

Clears the content of the selected cells, as Delete does; formats and styles stay.

<a id="commitedit"></a>
### CommitEdit()

```csharp
public bool CommitEdit()
```

Enters the text being typed into the active cell, as Enter does, and ends editing; true also when nothing is being edited. A formula that does not parse keeps the editor open, with the reason shown and the caret where the formula went wrong, and gives false.

<a id="copy"></a>
### Copy()

```csharp
public void Copy()
```

Puts the selected cells on the clipboard as Excel pastes them: as text with tabs between cells, and as an HTML table with their styles. Ctrl+C and `ApplicationCommands.Copy` do it too.

<a id="cut"></a>
### Cut()

```csharp
public void Cut()
```

Cuts the selected cells, as Ctrl+X and `ApplicationCommands.Cut` do in Excel: they are copied, and the next paste moves them, formulas and formats with them; until then they stay. Escape or another change forgets the cut.

<a id="deletecells-deleteshift"></a>
### DeleteCells(DeleteShift)

```csharp
public void DeleteCells(DeleteShift shift)
```

Deletes the selected cells, moving the cells below or on the right into their place, as Excel's Delete dialog does.

**Parameters**

- `shift`: Which cells take the place of the deleted ones.

<a id="deletecolumns"></a>
### DeleteColumns()

```csharp
public void DeleteColumns()
```

Deletes the selection's columns.

<a id="deleterows"></a>
### DeleteRows()

```csharp
public void DeleteRows()
```

Deletes the selection's rows, as Ctrl+Minus does with rows selected.

<a id="filldown"></a>
### FillDown()

```csharp
public void FillDown()
```

Copies the selection's top row into the rows below it, formulas following, as Ctrl+D does; with one row selected, the row above it into it (see [GridEditor.FillDown](SharpCell.Grid.GridEditor.md#filldown-worksheet-cellarea)).

<a id="fillright"></a>
### FillRight()

```csharp
public void FillRight()
```

Copies the selection's left column into the columns right of it, as Ctrl+R does; see [SpreadsheetView.FillDown](SharpCell.Grid.Wpf.SpreadsheetView.md#filldown).

<a id="hidecolumns"></a>
### HideColumns()

```csharp
public void HideColumns()
```

Hides the selection's columns, as Ctrl+0 does.

<a id="hiderows"></a>
### HideRows()

```csharp
public void HideRows()
```

Hides the selection's rows, as Ctrl+9 does.

<a id="insertcells-insertshift"></a>
### InsertCells(InsertShift)

```csharp
public void InsertCells(InsertShift shift)
```

Inserts empty cells in place of the selection, moving the cells beside it down or right, as Excel's Insert dialog does.

**Parameters**

- `shift`: Where the cells beside the selection go.

<a id="insertcolumns"></a>
### InsertColumns()

```csharp
public void InsertColumns()
```

Inserts as many columns as are selected before the selection's first column.

<a id="insertrows"></a>
### InsertRows()

```csharp
public void InsertRows()
```

Inserts as many rows as are selected before the selection's first row, as Ctrl+Plus does with rows selected.

<a id="opendeletedialog"></a>
### OpenDeleteDialog()

```csharp
public void OpenDeleteDialog()
```

Opens Excel's Delete dialog for the selection: shift cells left or up, or delete entire rows or columns.

<a id="openinsertdialog"></a>
### OpenInsertDialog()

```csharp
public void OpenInsertDialog()
```

Opens Excel's Insert dialog for the selection: shift cells right or down, or insert entire rows or columns. Ctrl+Plus opens it when the selection is not whole rows or columns.

<a id="paste"></a>
### Paste()

```csharp
public void Paste()
```

Pastes the text on the clipboard at the selection's top-left cell, as Ctrl+V and `ApplicationCommands.Paste` do: text copied from Excel goes in cell by cell, each read as typed. After [SpreadsheetView.Cut](SharpCell.Grid.Wpf.SpreadsheetView.md#cut), the cut cells move there instead, formulas and formats with them. The pasted cells are selected.

<a id="redo"></a>
### Redo()

```csharp
public void Redo()
```

Redoes the last undone change and selects its cells, as Ctrl+Y does.

<a id="reloadlayout"></a>
### ReloadLayout()

```csharp
public void ReloadLayout()
```

Takes the sheet's column widths, row heights, hidden rows and columns and frozen panes again.

<a id="restyle-func-cellstyle-cellstyle"></a>
### Restyle(Func<CellStyle, CellStyle>)

```csharp
public void Restyle(Func<CellStyle, CellStyle> change)
```

Changes the style of the selected cells: the function gets each cell's style and gives the new one.

<a id="setborders-borderedges-cellborder"></a>
### SetBorders(BorderEdges, CellBorder)

```csharp
public void SetBorders(BorderEdges edges, CellBorder? border)
```

Puts a border on edges of the selection, or takes it off with null, as Excel's Borders menu does; see [GridEditor.SetBorders](SharpCell.Grid.GridEditor.md#setborders-worksheet-cellarea-borderedges-cellborder).

<a id="setfill-cellcolor"></a>
### SetFill(CellColor?)

```csharp
public void SetFill(CellColor? color)
```

Fills the selected cells with a colour, or takes their fill off with null, as Excel's Fill Color does.

<a id="setfontcolor-cellcolor"></a>
### SetFontColor(CellColor?)

```csharp
public void SetFontColor(CellColor? color)
```

Gives the selected cells' text a colour, or the automatic colour with null, as Excel's Font Color does.

<a id="setnumberformat-string"></a>
### SetNumberFormat(string)

```csharp
public void SetNumberFormat(string format)
```

Gives the selected cells a number format, as Excel's Number Format box does.

<a id="shownextsheet-int"></a>
### ShowNextSheet(int)

```csharp
public bool ShowNextSheet(int direction = 1)
```

Shows the next sheet of the workbook, or with -1 the one before, as Ctrl+Page Down and Ctrl+Page Up do; false when there is none that way.

<a id="togglebold"></a>
### ToggleBold()

```csharp
public void ToggleBold()
```

Makes the selected cells bold, or not bold when the active cell is, as Ctrl+B does.

<a id="toggleitalic"></a>
### ToggleItalic()

```csharp
public void ToggleItalic()
```

Makes the selected cells italic, or not italic when the active cell is, as Ctrl+I does.

<a id="togglestrikethrough"></a>
### ToggleStrikethrough()

```csharp
public void ToggleStrikethrough()
```

Strikes the selected cells through, or not when the active cell is, as Ctrl+5 does.

<a id="toggleunderline"></a>
### ToggleUnderline()

```csharp
public void ToggleUnderline()
```

Underlines the selected cells, or takes the underline off when the active cell has one, as Ctrl+U does.

<a id="undo"></a>
### Undo()

```csharp
public void Undo()
```

Undoes the last change to the cells and selects them, as Ctrl+Z does.

<a id="unhidecolumns"></a>
### UnhideColumns()

```csharp
public void UnhideColumns()
```

Shows the hidden columns among the selection's, as Ctrl+Shift+0 does.

<a id="unhiderows"></a>
### UnhideRows()

```csharp
public void UnhideRows()
```

Shows the hidden rows among the selection's, as Ctrl+Shift+9 does.
