# Saving to an Excel File

Learn how you can save data to an Excel-formatted (BIFF8 format or XLSX) file or stream.

## Content

You can save data to an Excel-formatted (BIFF8 format or XLSX) file or stream. There are multiple [SaveExcel](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.FpSpread.SaveExcel.html) methods each with several options. For instance, you can specify whether headers are saved with the data using the setting of the [IncludeHeaders](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.IncludeHeaders.html) enumeration. Use the ExcelSaveFlags.UseOOXMLFormat with the ExcelSaveFlags enumeration to save to an XLSX format.
The document caching option in the ExcelOpenFlags or ExcelSaveFlags enumeration allows users to open, edit, and save without the loss of advanced document content and formatting. Advanced content includes items such as macros, ActiveX controls, data connections, and so on. Consider the following when using the document caching option:

* Advanced document content is preserved (lossless) only if the opening file format is similar to the saving file format.
* If the advanced document content uses files besides the xls(x) file, then the additional files need to be in the same folder with the
    xls(x) file.
* To keep any document caching settings (changes would be lost during a postback), open the original file with the document caching only setting and then save the file using the document caching setting.

You can also save a file from inside Spread Designer.
The SaveExcel button on the CommandBar allows users to export a spreadsheet into an Excel file. To display this button on the CommandBar, users need to set the [ShowExcelButton](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.CommandBarInfo.ShowExcelButton.html) property in the [CommandBarInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.CommandBarInfo.html) class to true.
For more information on exporting spreadsheets to excel files, see [Working with the SaveExcel button on the CommandBar](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-interaction/spweb-interact-toolbars/working-with-the-save-excel-button-on-the-commandbar).
For instructions for opening Excel-compatible files, see [Opening an Excel-Formatted File](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-fileops/spweb-fileopen/spweb-fileopenexcel).
For more information about how the data and formatting is exported to the Excel file format, see the [Import and Export Reference](/spreadnet/docs/latest/online-asp/overview/spweb-importexportref).

## Using Code

Use the FpSpread object’s [SaveExcel](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.FpSpread.SaveExcel.html) method, providing the path and file name for the file to save, or providing additional information using one of the overloaded methods.

## Example

The first example saves the data in a FpSpread component to an Excel-formatted file and specifies that both row and column headers are included in the output. The second example saves to a stream.

```csharp
// Save data to Excel-formatted file, including headers.
FpSpread1.SaveExcel("C:\\excelfile.xls", FarPoint.Web.Spread.Model.IncludeHeaders.BothCustomOnly);
// Save data to memory stream and then load in second component.
System.IO.MemoryStream s = new System.IO.MemoryStream();
FpSpread1.SaveExcel(s);
s.Position = 0;
FpSpread2.OpenExcel(s);
s.Close();
```

```vbnet
' Save data to an Excel-formatted file, including headers.
FpSpread1.SaveExcel("C:\excelfile.xls", FarPoint.Web.Spread.Model.IncludeHeaders.BothCustomOnly)
' Save data to memory stream and then load in second component.
Dim s As New System.IO.MemoryStream()
FpSpread1.SaveExcel(s)
s.Position = 0
FpSpread2.OpenExcel(s)
s.Close()
```

## Using the Spread Designer

1. Select the **File** menu.
2. Choose the **Save** option.
    The **Save As** dialog appears.
3. For the **Save As** type, select Excel files (.xls or .xlsx).
4. Specify the path and file name to which to save the file, and then click **Save**.
5. Click **OK** to close the Spread Designer.

## See Also

[ExcelSaveFlags Enumeration](/spreadnet/api/latest/online-asp/FarPoint.Excel/FarPoint.Excel.ExcelSaveFlags.html)