ExportRangeToTextFile Method
Applies To
fpSpread control
Description
Saves the specified range of cells in a sheet to a text file.
Syntax
BOOL CSpreadSheet::ExportRangeToTextFile(long Col, long Row, long Col2, long Row2, LPCTSTR FileName, LPCTSTR CellDelim, LPCTSTR ColDelim, LPCTSTR RowDelim, long Flags, LPCTSTR LogFile);
fpSpread1.ExportRangeToTextFile(ByVal Col As Long, ByVal Row As Long, ByVal Col2 As Long, ByVal Row2 As Long, ByVal FileName As String, ByVal CellDelim As String, ByVal ColDelim As String, ByVal RowDelim As String, ByVal Flags As ExportRangeToTextFileConstants, ByVal LogFile As String) As Boolean
Parameters
The following parameters are available:
Parameter | Description | ||
---|---|---|---|
Col | Column number of first column in range to save to text | ||
Row | Row number of first row in range to save to text | ||
Col2 | Column number of last column in range to save to text | ||
Row2 | Row number of last row in range to save to text | ||
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: | |||
ExportRangeToTextFileCreateNewFile | 1 | To create a new text file | |
ExportRangeToTextFileAppendToExistingFile | 2 | To append to an existing text file | |
Use the following value: | |||
ExportRangeToTextFileUnformattedData | 4 | To export data as unformatted data | |
Use one or both of the following values: | |||
ExportRangeToTextFileColHeaders | 8 | To export column header text | |
ExportRangeToTextFileRowHeaders | 16 | To export row header text | |
ExportRangeToTextFileAllHeaders | 24 | To export all header text | |
Use the following value: | |||
ExportRangeToTextFileCheckBoxFalse | 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 ExportRangeToTextFile method to save a range of cells in a sheet to an ANSI text file. If you want to save a range of cells to a Unicode text file, use the ExportRangeToTextFileU method.
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.
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 the Col, Row, Col2, and Row2 parameters to specify which cells to export. For example, you can use the BlockSelected event to determine which range of cells the user has selected, and then pass those parameters to the ExportRangeToTextFile method to export the selected range.
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. |
Only the specified cells in the specified sheet are exported to the text file. If you want to export an entire sheet, use the ExportToTextFile method instead.
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
ExportRangeToTextFileU, ExportToTextFile, ExportToTextFileU, LoadTextFile, SaveTabFile methods
DLL Correspondence
SSExportRangeToTextFile function