Spread for WPF lets you store, manipulate, and display data in a worksheet.
A worksheet is comprised of numerous cells where you can enter data, use formulas, perform calculations, analyze data, and review results. Each cell is represented by the intersection of a row and a column. In a worksheet, rows are labeled with numeric characters, such as 1, 2, 3…, and columns are labeled with alphabetical characters, such as A, B, C... For example, cell B4 refers to the cell in column B and row 4 in a worksheet.
The following sections give you information about various operations that can be performed on worksheets.
All worksheets in a workbook are stored in the Worksheets collection. You can access a specific worksheet by its index or its name. Additionally, you can use the ActiveSheet property to get the active sheet in a workbook.
Refer to the following example code to get a specific worksheet.
A workbook can contain multiple worksheets. However, a workbook has only one worksheet by default.
You can add one or more worksheets to the workbook. Using the Add method of the IWorksheets interface, you can add a new worksheet to a workbook before or after a specific worksheet.
Refer to the following example code to add new worksheets.
Additionally, Spread for WPF also allows you to add multiple worksheets in the XAML view. To do this, you must define all the worksheets inside the <gss:GcSpreadSheet.Sheets> element.
Refer to the following example code to create two worksheets in a workbook with the names "Sheet1" and "Sheet2", where Sheet1 has one column and five rows and Sheet2 has two columns and ten rows.
XAML |
Copy Code
|
---|---|
<Grid> <gss:GcSpreadSheet x:Name="spreadSheet1"> <gss:GcSpreadSheet.Sheets> <gss:SheetInfo Name="Sheet1" RowCount="5"> <gss:SheetInfo.Columns> <gss:ColumnInfo/> </gss:SheetInfo.Columns> </gss:SheetInfo> <gss:SheetInfo Name="Sheet2" RowCount="10"> <gss:SheetInfo.Columns> <gss:ColumnInfo/> <gss:ColumnInfo/> </gss:SheetInfo.Columns> </gss:SheetInfo> </gss:GcSpreadSheet.Sheets> </gss:GcSpreadSheet> </Grid> |
The active sheet is the selected worksheet that currently receives any user interaction in the workbook. You can set a specific worksheet as active using the Activate method of the IWorksheet interface.
Refer to the following example code to set the active worksheet.
If you have multiple worksheets, you can move them to a specific location on the tab strip. While moving, a worksheet does not change its name. To move a worksheet within a workbook, use the Move method of the IWorksheet interface.
Refer to the following example code to move your worksheet to another location.
You can copy a worksheet to a new worksheet using the Copy method of the IWorksheet interface. The copied worksheet looks exactly the same as the original worksheet.
Refer to the following example code to copy your worksheet.
You can hide a specific worksheet from a workbook. When you hide a worksheet, the corresponding sheet tab disappears from the tab strip. You can manage the visibility of a worksheet using the SheetVisibility enumeration values.
To hide a worksheet, you can set the value of the SheetVisibility enumeration to Hidden. However, the hidden worksheet remains a part of your workbook and can be displayed again by changing the value to Visible.
Refer to the following example code to hide a specific worksheet.
You can protect a worksheet with a password so that other users cannot edit the data accidentally or intentionally. To restrict editing of a worksheet, use the Protect method of the IWorksheet interface.
Refer to the following example code to protect a worksheet from any modifications.
You can delete one or more worksheets from a workbook at once using the Delete method of the IWorksheet interface. The deleted worksheets will be automatically removed from the worksheets collection.
Refer to the following example code to delete a specific sheet from the workbook.
Gridlines are used to distinguish between cells on a worksheet. You can change the default color of the gridlines by using the GridlineColorIndex property.
The DisplayGridlines property of the IWorksheetView interface allows you to show or hide gridlines. By default, the property value is set to true. To hide gridlines, you can change this value to false.
Refer to the following example code to customize the gridlines on a worksheet.