Spread Windows Forms 12.0 Product Documentation
Saving to an Excel File
Spread Windows Forms 12.0 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 file in the following formats by selecting different options of ExcelSaveFlags enumeration.

In order to save data to Excel Workbook format, use the UseOOXMLFormat option. While exporting data to a .xlsx file, if you want to save the spreadsheet data along with all the spreadsheet settings to an Excel file, you need to select one more option - the Exchangeable option. The Exchangeable option works with the UseOOXMLFormat option. 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 put a number or date in an Excel cell and the width of the column is not large enough to display the data, then Excel shows the cell filled with ###. Make sure the width of the column is set wide enough to display the data in the exported Excel-formatted file.

For more details on the methods used, refer to SaveExcel methods of the FpSpread class. There are many different SaveExcel methods. Some of the methods have a saveFlags option. This allows you to specify headers and other options. Headers are exported as frozen columns and rows.

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, and so on.

For more information about how the data is saved to an Excel-formatted file, see the Import and Export Reference.

Using Code

Use one of the SaveExcel methods of the FpSpread class, providing the path and file name for the file to save, and any additional parameters depending on the particular method.

Example

This example code saves the spread data along with all the settings to an Excel file using the UseOOXMLFormat option and the Exchangeable option.

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)

Using the Spread Designer

  1. From the File menu, choose Save.

    The Save As dialog appears.

  2. Change the Save as type box to Excel files (*.xls).
  3. Specify the path and file name to which to save the file.
  4. Select Exchangeable option and UseOOXMLFormat option from Select Excel Save Flags drop-down list, and then click Save.

    If the file is saved successfully, a message appears stating the file has been saved.

  5. Click OK to close the Spread Designer.

Example

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)

Using the Spread Designer

  1. From the File menu, choose Save.

    The Save As dialog appears.

  2. Change the Save as type box to Excel files (*.xls).
  3. 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.

  4. Click OK to close the Spread Designer.