Different Ways to Save Your Files
Aspose.Cells API provides a class named Workbook that represents an Excel file and provides all necessary properties and methods that developers may need to work with their Excel files. Workbook class provides a save method that is used to save Excel files. The save method has many overloads that are used to save Excel files in different ways.
Developers can also specify the file format in which their files should be saved. The files can be saved in several formats such as XLS, SpreadsheetML, CSV, Tab Delimited, Tab-separated values TSV, XPS and many more. These file formats are specified using the SaveFormat enumeration.
SaveFormat enumeration contains many pre-defined file formats (that can be chosen by you) as follows:
File Format Types
API tries to detect the appropriate format from the file extension specified in the first parameter to the
Represents a CSV file
Represents an XLS file that is the default format for Excel 1997 to 2003 revisions
Represents an Excel 2007 binary XLSB file
Represents an Excel XLAM file
Represents XML-based XLSM file
Represents an Office Open XML SpreadsheetML file
Represents an Excel Macro-enabled template file
Represents an Excel template file
Represents a SpreadSheetML file
|TSV||Represents a Tab-separated values file|
Represents a Tab Delimited text file
Represents an HTML file(s)
Represents an MHtml file(s)
Represents an OpenDocument Spreadsheet file
Represents a PDF Document
Represents an XML-based Scalable Vector Graphics (SVG) file
Represents a Tagged Image File Format (TIFF) file
Represents an XML Paper Specification (XPS) file
Normally, there are two ways to save Excel files as follows:
- Saving the file to some location
- Saving the file to a stream
Saving File to Some Location
If developers need to save their files to some storage location then they can simply specify the file name (with its complete storage path) and desired file format (using the SaveFormat enumeration) while calling the save method of Workbook object.
Saving Workbook to Text or CSV Format
Sometimes, you want to convert or save a workbook with multiple worksheets into text format. For text formats (for example TXT, TabDelim, CSV etc.), by default both Microsoft Excel and Aspose.Cells save the contents of the active worksheet only.
The following code example explains how to save an entire workbook into text format. Load the source workbook which could be any Microsoft Excel or OpenOffice spreadsheet file (so XLS, XLSX, XLSM, XLSB, ODS and so on) with any number of worksheets.
When the code is executed, it converts the data of all sheets in the workbook to TXT format.
You can modify the same example to save your file to CSV. By default, TxtSaveOptions.Separator is a comma, so do not specify a separator if saving to CSV format.
Saving Text Files with Custom Separator
Text files contain spreadsheet data without formatting. The file is a kind of plain text file that can have some customized delimiters between its data.
Saving File to a Stream
If developers need to save their files to a Stream then they should create a FileOutputStream object and then save the file to that Stream object by calling the save method of Workbook object. Developers can also specify the desired file format (using the SaveFormat enumeration) while calling the save method.
Saving File to Other Format
Set ContentCopyForAccessibility option
With the PdfSaveOptions class, you can get or set the PDF AccessibilityExtractContent option to control the content access in the converted PDF. It means it allows screen reader software to utilize the text within the PDF file for reading the PDF file. You can disable it by applying a change permissions password and deselecting the two items in the screenshot here.
Export Custom properties to PDF
With the PdfSaveOptions class, you can export the custom properties in source workbook to the PDF. PdfCustomPropertiesExport enumerator is provided for specifying the way by which properties are exported. These properties can be observed in Adobe Acrobat Reader by clicking on File and then properties option as shown in the following image. Template file "sourceWithCustProps.xlsx" can be downloaded here for testing and output PDF file "outSourceWithCustProps" is available here for analysis.