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

# XlsxWriter

```csharp
public static class XlsxWriter
```

Namespace `SharpCell.Xlsx` · package `SharpCell.Xlsx`

Saves a workbook as an .xlsx file: values, formulas, styles, number formats, sizes, merged cells, panes, sheets, defined names and tables. A workbook read by [XlsxReader](SharpCell.Xlsx.XlsxReader.md) is saved into the file it was read from: everything SharpCell does not model (charts, pivot tables, comments, conditional formats, macros) is copied unchanged, and so is every cell that did not change. A workbook built in code becomes a new file. Call [Workbook.Recalculate](SharpCell.Workbook.md#recalculate-cancellationtoken) before saving.

## Methods

<a id="save-workbook-stream"></a>
### Save(Workbook, Stream)

```csharp
public static void Save(Workbook workbook, Stream stream)
```

Saves the workbook to a stream, which is left open.

**Parameters**

- `workbook`: A recalculated workbook, read by [XlsxReader](SharpCell.Xlsx.XlsxReader.md) or built in code.
- `stream`: Where the .xlsx content goes; it need not be seekable. Nothing is written when the save is refused.

**Exceptions**

- `NotSupportedException`: A cell of an Excel data table changed, or a cell holds `#SPILL!` or `#CALC!` as a value.
- `InvalidOperationException`: Some formulas are not calculated: call [Workbook.Recalculate](SharpCell.Workbook.md#recalculate-cancellationtoken) first; or the workbook has no sheets.
- `XlsxWriteException`: SharpCell could not calculate some formulas; see [XlsxWriteOptions.KeepUncalculated](SharpCell.Xlsx.XlsxWriteOptions.md#keepuncalculated).

<a id="save-workbook-stream-xlsxwriteoptions"></a>
### Save(Workbook, Stream, XlsxWriteOptions)

```csharp
public static void Save(Workbook workbook, Stream stream, XlsxWriteOptions options)
```

Saves the workbook to a stream, which is left open.

**Parameters**

- `workbook`: A recalculated workbook, read by [XlsxReader](SharpCell.Xlsx.XlsxReader.md) or built in code.
- `stream`: Where the .xlsx content goes; it need not be seekable. Nothing is written when the save is refused.
- `options`: What to do with formulas SharpCell cannot calculate.

**Exceptions**

- `NotSupportedException`: A cell of an Excel data table changed, or a cell holds `#SPILL!` or `#CALC!` as a value.
- `InvalidOperationException`: Some formulas are not calculated: call [Workbook.Recalculate](SharpCell.Workbook.md#recalculate-cancellationtoken) first; or the workbook has no sheets.
- `XlsxWriteException`: SharpCell could not calculate some formulas and `options` does not keep them.

<a id="save-workbook-string"></a>
### Save(Workbook, string)

```csharp
public static void Save(Workbook workbook, string path)
```

Saves the workbook to a file, replacing it if it exists (the file it was read from too).

**Parameters**

- `workbook`: A recalculated workbook, read by [XlsxReader](SharpCell.Xlsx.XlsxReader.md) or built in code.
- `path`: Path of the .xlsx file to write (.xlsm for a macro-enabled workbook read from one). The file is replaced only once the new one is complete.

**Exceptions**

- `NotSupportedException`: A cell of an Excel data table changed, or a cell holds `#SPILL!` or `#CALC!` as a value.
- `InvalidOperationException`: Some formulas are not calculated: call [Workbook.Recalculate](SharpCell.Workbook.md#recalculate-cancellationtoken) first; or the workbook has no sheets.
- `XlsxWriteException`: SharpCell could not calculate some formulas; see [XlsxWriteOptions.KeepUncalculated](SharpCell.Xlsx.XlsxWriteOptions.md#keepuncalculated).

<a id="save-workbook-string-xlsxwriteoptions"></a>
### Save(Workbook, string, XlsxWriteOptions)

```csharp
public static void Save(Workbook workbook, string path, XlsxWriteOptions options)
```

Saves the workbook to a file, replacing it if it exists (the file it was read from too).

**Parameters**

- `workbook`: A recalculated workbook, read by [XlsxReader](SharpCell.Xlsx.XlsxReader.md) or built in code.
- `path`: Path of the .xlsx file to write (.xlsm for a macro-enabled workbook read from one). The file is replaced only once the new one is complete.
- `options`: What to do with formulas SharpCell cannot calculate.

**Exceptions**

- `NotSupportedException`: A cell of an Excel data table changed, or a cell holds `#SPILL!` or `#CALC!` as a value.
- `InvalidOperationException`: Some formulas are not calculated: call [Workbook.Recalculate](SharpCell.Workbook.md#recalculate-cancellationtoken) first; or the workbook has no sheets.
- `XlsxWriteException`: SharpCell could not calculate some formulas and `options` does not keep them.
