ExportToTextFile Method
Applies To
fpSpread control
Description
Saves a sheet to a text file and lets you specify the delimiters.
Syntax
BOOL CSpreadSheet::ExportToTextFile(LPCTSTR FileName, LPCTSTR CellDelim, LPCTSTR ColDelim, LPCTSTR RowDelim, long Flags, LPCTSTR LogFile);
fpSpread1.ExportToTextFile(ByVal FileName As String, ByVal CellDelim As String, ByVal ColDelim As String, ByVal RowDelim As String, ByVal Flags As ExportToTextFileConstants, ByVal LogFile As String) As Boolean
Parameters
The following parameters are available:
Parameter | Description | ||
---|---|---|---|
FileName | Path and file name of the text file to create | ||
CellDelim | Cell delimiter For more information about the cell delimiter, see the Remarks section. |
||
ColDelim | Column delimiter | ||
RowDelim | Row delimiter If you do not provide a row delimiter, the control uses a carriage return/line feed as the delimiter. |
||
Flags | Whether to append or over-write the file, whether to export formatted or unformatted data, and whether to export column and row headers You must specify whether to append or create a new file. If you do not specify other options, formatted data will be exported, without column and row header text. Use the OR operator and combine the following values as indicated: |
||
Constant | Value | Description | |
Use one of the following values: | |||
ExportToTextFileCreateNewFile | 1 | To create a new text file | |
ExportToTextFileAppendToExistingFile | 2 | To append to an existing text file | |
Use the following value: | |||
ExportToTextFileUnformattedData | 4 | To export data as unformatted data | |
Use one or both of the following values: | |||
ExportToTextFileColHeaders | 8 | To export column header text | |
ExportToTextFileRowHeaders | 16 | To export row header text | |
Use the following value: | |||
ExportToTextFileCheckBoxFalse | 32 | Writes the false value as 0. | |
LogFile | Path and file name of log file to create If you do not provide a file name, the export will not create a log file. If you do not want to create a log file, set this parameter to "". |
Remarks
Use the ExportToTextFile method to save a sheet to an ANSI text file. If you want to save the sheet to a Unicode text file, use the ExportToTextFileU method.
This method is called for the current sheet setting unless you first set the Sheet property to specify the sheet with which you want to work.
Use strings to specify the delimiters to separate your data in the text file. If you do not want to provide a column delimiter, specify "" as the delimiter. If you do not provide a row delimiter, the control uses a carriage return/line feed as the delimiter.
You can use more than one character as the delimiter, enabling you to insert field names around data. You can use the Visual Basic Chr() function in a delimiter; for example, use Chr(10) to specify a line feed.
If you have specified a column or row delimiter, a cell delimiter is automatically provided. The cell delimiter is provided if one of the following is true:
- The data contains a character you have specified as a delimiter.
- The data contains a double quote (").
By default, the control provides double quotes (") as the cell delimiter. You can specify another delimiter, if you prefer.
If the data contains the character used as the column or row delimiter, the entire cell data is placed between the cell delimiter character. For example, if the column delimiter is a comma, the data ab,cd becomes "ab,cd". If the data contains the character defined as the cell delimiter, the character in the data is preceded by another cell delimiter; for example, ab,"cd becomes "ab,""cd". Only cells that have data that contains a delimiter character have cell delimiters applied to them.
Use the Flags parameter to specify whether formatted or unformatted data is saved to the text file. For more information about formatted and unformatted data, see Formatted and Unformatted Data. Also use the Flags parameter to specify whether to append the data to an existing file, or to create a new file, and to specify whether column and row headers are exported.
By default, text files with custom delimiters created using Spread or the Spread Designer have the extension .TXT. However, you may use any extension.
Tip: You might want to save to a Spread (.SS8) file in addition to exporting it to text so that you can open the Spread (.SS8) file for future modifications. |
The following table summarizes the formats to which you can save data from a workbook or sheet:
To Save To . . . | Use Method |
---|---|
Binary file (proprietary format) | SaveToFile |
Tab-delimited file | SaveTabFile or SaveTabFileU |
Delimited file (offers user-defined delimiters) | ExportToTextFile or ExportRangeToTextFile or ExportToTextFileU or ExportRangeToTextFileU |
Excel-formatted file | ExportExcelBook or ExportToExcel |
HTML file | ExportToHTML or ExportRangeToHTML |
XML file | ExportToXML or ExportRangeToXML |
XML buffer | ExportToXMLBuffer or ExportRangeToXMLBuffer |
An array | GetArray |
Note that the SaveTabFile and the ExportRangeToTextFile and ExportToTextFile methods are similar. If you want to save the entire sheet to a tab-delimited file, you might find it faster to use the SaveTabFile method. If you want to save only a portion of the sheet, or if you want to define your own delimiters, use the ExportRangeToTextFile or ExportToTextFile method.
Return Type
True if successful; otherwise, False.
See Also
Formatted and Unformatted Data
Saving to a Text File
Sheet property
ExportRangeToTextFile, ExportRangeToTextFileU, ExportToTextFileU, LoadTextFile, SaveTabFile methods
DLL Correspondence
SSExportToTextFile function