Spread for ASP.NET 12 Product Documentation
Saving to an Excel File
Spread for ASP.NET 12 Product Documentation > Developer's Guide > Managing File Operations > Saving Data to a File > Saving to an Excel File

You can save data to an Excel-formatted (BIFF8 format or XLSX) file or stream. There are multiple SaveExcel methods each with several options. For instance, you can specify whether headers are saved with the data using the setting of the IncludeHeaders 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:

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 property in the CommandBarInfo class to true.

For more information on exporting spreadsheets to excel files, see Working with the SaveExcel button on the CommandBar.

For instructions for opening Excel-compatible files, see Opening an Excel-Formatted File.

For more information about how the data and formatting is exported to the Excel file format, see the Import and Export Reference.

Using Code

Use the FpSpread object’s SaveExcel 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.

C#
Copy Code
// 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();
VB
Copy Code
' 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