You can save data to an excel file using one of the SaveExcel methods of the FpSpread class. This method accepts the path and file name for the file to save, and any additional parameters depending on the particular method.
One of the parameters used in the SaveExcel method is the ExcelSaveFlags enumeration. It provides the following formats to save data in Excel.
To save data to Excel Workbook format, use the UseOOXMLFormat option. If you want to save the spreadsheet data along with all the spreadsheet settings to an Excel file, you need to use the Exchangeable option as well. This option helps to retain all the data even after exporting and importing (with the ExcelOpenFlags Exchangeable option) the Excel file in Spread.NET.
By default when you save to Excel, whatever is stored in the data model of the Spread is written out to a file or stream in BIFF8 format.
If you are saving a spreadsheet in an Excel file and it contains an image in an image cell type, the following behavior can be observed:
The following example saves the spread data along with all the settings to an Excel file using the SaveExcel method which has ExcelSaveFlags options UseOOXMLFormat and Exchangeable as arguments.
C# |
Copy Code
|
---|---|
// Save spread data to an Excel file (.xlsx). fpSpread1.SaveExcel("C:\\excelfile.xlsx", FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat | FarPoint.Excel.ExcelSaveFlags.Exchangeable); |
VB |
Copy Code
|
---|---|
' Save spread data to an Excel file (.xlsx). fpSpread1.SaveExcel("C:\\excelfile.xlsx", FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat | FarPoint.Excel.ExcelSaveFlags.Exchangeable) |
The Save As dialog appears.
If the file is saved successfully, a message appears stating the file has been saved.
This example code saves the data in a Spread component to an Excel-formatted file and specifies that both row and column headers are included in the output.
C# |
Copy Code
|
---|---|
// Save the data to an Excel-formatted file, including headers. fpSpread1.SaveExcel("C:\\excelfile.xls", FarPoint.Win.Spread.Model.IncludeHeaders.BothCustomOnly); |
VB |
Copy Code
|
---|---|
' Save the data to an Excel-formatted file, including headers. fpSpread1.SaveExcel("C:\excelfile.xls", FarPoint.Win.Spread.Model.IncludeHeaders.BothCustomOnly) |
The DocumentCaching option in the ExcelOpenFlags or ExcelSaveFlags enumeration allows you 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, and so on.
For more information about how the data is saved to an Excel-formatted file, see the Import and Export Reference.