Spread for WPF allows you to save/export the content of a workbook or worksheet in various formats, such as excel, pdf, xml, and html using the SaveAs method of the IWorkbook interface. To specify the file format, when saving, use the fields of the FileFormat enumeration.
You can save the content of spread to the default Excel format using the OpenXMLWorkbook field of the FileFormat enumeration.
Refer to the following example code to save data to a .xlsx file.
You can also save data as a macro-enabled workbook, which is preferred if your file contains macros. Use the OpenXMLWorkbookMacroEnabled field of the FileFormat enumeration to save data directly as .xlsm files.
Refer to the following example code to save to a .xlsm file.
You can export data to the Comma-Separated Value (.csv) files. A CSV file is a plain text file that uses a comma to separate the values where each row of data starts from a new line. To save data as a .csv file, use the CSV field of the FileFormat enumeration.
Note: Worksheet headers cannot be exported to CSV files.
Refer to the following example code to save data to a .csv file.
You can export a workbook/worksheet to a Portable Document File (PDF). This type of format is good for sharing non-editable versions of your data. To save as a .pdf file, use the PDF field of the FileFormat enumeration.
Refer to the following example code to save data to a .pdf file.
Hypertext Markup Language (HTML) files can be accessed with a web browser. You can export a workbook or worksheet to an HTML file. To save as a .html file, use the Html field of the FileFormat enumeration.
Refer to the following example code that saves the data from a workbook to a .html file.
Additionally, while saving a workbook, you can also specify various options for exporting data by setting the following values of the ExportOptions enumeration in the Options property of the ExportContext class.
Value | Description |
ColumnHeader | Indicates that the column header will be exported as top rows of the worksheet. |
DataOnly | Indicates that only cell values are exported. |
Default | The default export options. |
Exchangeable | Spread data will be saved as extension of OpenXML file format. |
ExternalReference | Indicates that the saved file will be used for external references to the workbook. |
IncludeAutoMergedCells | Indicates that the automatically merged cells will be exported. |
NoFormulas | Indicates that cell formulas aren't exported. |
None | No option is available. |
PreferTextOnExport | The cell text will be exported if there is an explicit cell type. |
RowHeader | Indicates that the row header will be exported as left columns of the worksheet. |
In the following example code, ExportOptions.ColumnHeader is specified to include the column headers in the exported Excel file.