# Workbook

Provides a list of the workbook tasks along with all the necessary properties and methods available in Spread for WPF.

## Content

A workbook is a spreadsheet document comprising one or more worksheets. A collection of workbooks creates a workbook set. By default, a workbook set contains a single workbook and a workbook contains one worksheet (Sheet1). Spread for WPF provides all the essential properties and methods needed to create a workbook and perform complex operations on data present in a spreadsheet.
You can perform the following actions in a workbook.

## Get a Workbook

You can get the workbook using the [Workbook](/spreadnet/api/latest/online-wpf/GrapeCity.Wpf.SpreadSheet/GrapeCity.Wpf.SpreadSheet.GcSpreadSheet.Workbook.html) property of the **GcSpreadSheet** class.
Refer to the following example code to access a workbook.
**C#**

```csharp
// Access spreadSheet1 component as the workbook.
GrapeCity.Spreadsheet.IWorkbook workbook = spreadSheet1.Workbook;
```

**VB**

```auto
' Access spreadSheet1 component as the workbook.
Dim workbook As GrapeCity.Spreadsheet.IWorkbook = spreadSheet1.Workbook
```

## Add a Workbook

You can create one or more new workbooks within a workbook set using the [Add](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorkbooks.Add.html) method of the **IWorkbooks** interface.
Refer to the following example code to add a new workbook.
**C#**

```csharp
// Create a new workbook in the same workbook set.
GrapeCity.Spreadsheet.IWorkbook workbook = spreadSheet1.Workbook.WorkbookSet.Workbooks.Add("Book2");
```

**VB**

```auto
'Create a new workbook in the same workbook set.
Dim workbook As GrapeCity.Spreadsheet.IWorkbook = spreadSheet1.Workbook.WorkbookSet.Workbooks.Add("Book2")
```

## Open a Workbook

Once a workbook is created, you can open it to make any changes. To open an existing Excel workbook, you can use either [Open](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorkbooks.Open.html) method of **IWorkbooks** interface or [OpenExcel](/spreadnet/api/latest/online-wpf/GrapeCity.Wpf.SpreadSheet/GrapeCity.Wpf.SpreadSheet.GcSpreadSheet.OpenExcel.html) method of the **GcSpreadSheet** class.
When the **Open** method is used, it opens an existing workbook as a new workbook in the workbook set. However, it does not appear in the GcSpreadSheet control and GcSpreadSheet will show the content of its old workbook. Usually, this method is helpful when working with external references. For example, use a formula to refer to a cell range of another workbook.
On the other hand, the **OpenExcel** method opens an existing workbook in the GcSpreadSheet control. This method replaces the current workbook in the GcSpreadsheet control with the newly opened workbook.
Refer to the following example code to open an existing workbook.
**C#**

```csharp
// Open a workbook in a workbook set.
GrapeCity.Spreadsheet.IWorkbook workbook1 = spreadSheet1.Workbook.WorkbookSet.Workbooks.Open(@"D:\TestFile.xlsx");
// Open a workbook in GcSpreadSheet control.
spreadSheet1.OpenExcel(@"D:\TestFile.xlsx");
```

**VB**

```auto
' Open a workbook in a workbook set.
Dim workbook2 As GrapeCity.Spreadsheet.IWorkbook = spreadSheet1.Workbook.WorkbookSet.Workbooks.Open("D:\TestFile.xlsx")
' Open a workbook in GcSpreadSheet control.
spreadSheet1.OpenExcel("D:\TestFile.xlsx")
```

## Save a Workbook

You can save the changes made in the workbook by using the [SaveAs](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorkbook.SaveAs.html) method of the **IWorkbook** interface.
Refer to the following example code to save your workbook.
**C#**

```csharp
// Save the workbook.
spreadSheet1.Workbook.ActiveSheet.Cells[0, 0].Value = 123;
spreadSheet1.Workbook.ActiveSheet.Cells[0, 1].Value = 456;
spreadSheet1.Workbook.ActiveSheet.Cells[0, 2].Value = 789;
spreadSheet1.Workbook.SaveAs(@"SaveWorkbook.xlsx", GrapeCity.Spreadsheet.IO.FileFormat.OpenXMLWorkbook);
```

**VB**

```auto
' Save the workbook.
spreadSheet1.Workbook.ActiveSheet.Cells(0, 0).Value = 123
spreadSheet1.Workbook.ActiveSheet.Cells(0, 1).Value = 456
spreadSheet1.Workbook.ActiveSheet.Cells(0, 2).Value = 789
spreadSheet1.Workbook.SaveAs("SaveWorkbook.xlsx", GrapeCity.Spreadsheet.IO.FileFormat.OpenXMLWorkbook)
```

For more information about saving the workbook to different file formats, see [Save Files](/spreadnet/docs/latest/online-wpf/spreadwpffeatures/file-operations/savefiles).

## Protect a Workbook

Once a workbook is created, you can protect it from any modifications so that other users can't perform certain operations on it. To restrict editing of a workbook, use the [Protect](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorkbook.Protect.html) method of the **IWorkbook** interface.

> !type=note
> **Note**: This function is only supported in the Excel I/O scenarios.

**C#**

```csharp
// Protect workbook.
spreadSheet1.Workbook.Protect(GrapeCity.Spreadsheet.WorkbookLocks.All, "password");
```

**VB**

```auto
' Protect workbook.
spreadSheet1.Workbook.Protect(GrapeCity.Spreadsheet.WorkbookLocks.All, "password")
```

## Set Document Properties

Document properties contain information about a workbook, such as title, subject, author, subject, etc. Spread for WPF allows you to manage these properties within the workbook.
To customize the document properties, use the [BuiltinDocumentProperties](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorkbook.BuiltinDocumentProperties.html) property of the **IWorkbook** interface. This property accepts the [BuiltinDocumentProperties](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Core.BuiltinDocumentProperties.html) enumeration as a parameter to access all document properties, which can then be modified to meet your requirements.
Refer to the following example code to set the author name for a workbook.
**C#**

```csharp
// Set document properties.
spreadSheet1.Workbook.BuiltinDocumentProperties[GrapeCity.Core.BuiltinDocumentProperties.Company].Text = "AuthorName";
```

**VB**

```auto
'Set document properties.
spreadSheet1.Workbook.BuiltinDocumentProperties(GrapeCity.Core.BuiltinDocumentProperties.Company).Text = "AuthorName"
```

## Apply Theme to Workbook

You can change the default theme of a workbook to enhance the visual appearance of the worksheets. For example, when you apply a theme to a workbook, the styles of font, cell color, and sheet may change depending on the modified theme.
The [ApplyTheme](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorkbook.ApplyTheme.html) method of the **IWorkbook** interface is used to apply a theme to the current workbook. The easiest way to apply a custom theme is to pass a theme file. A theme file can be an XLSX or an theme file with extension \*.THMX.
Refer to the following example code to apply the Damask theme to the workbook.
**C#**

```csharp
// Apply a theme to the workbook.
spreadSheet1.Workbook.ApplyTheme("Damask.thmx");
```

**VB**

```auto
' Apply a theme to the workbook.
spreadSheet1.Workbook.ApplyTheme("Damask.thmx")
```