You can save data to an Excel-formatted (BIFF8 format or XLSX) file or stream. There are several 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 in order 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. The content can be 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. Advanced content could be macros, ActiveX controls, data connections, etc. In order 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.
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 Spread for ASP.NET Import and Export Reference.
Return to the overview at Saving Data to a File.
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
- Select the File menu.
- Choose the Save option.
The Save As dialog appears.
- For the Save As type, select Excel files (.xls or .xlsx).
- Specify the path and file name to which to save the file, and then click Save.
If the file is saved successfully, a message appears stating the file has been saved.
- Click OK to close the Spread Designer.