Spread Windows Forms 15.0
Spread Windows Forms 15.0 Product Documentation / Developer's Guide / File Operations / Saving Data to a File / Saving to an Excel File
In This Topic
    Saving to an Excel File
    In This Topic

    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.

    Export Image Cell Type to Excel

    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:

    Example

    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)
    
    Note: 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.

    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)
    

    Document Caching

    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.

    See Also