TCustomStringGrid.SaveToCSVStream procedure
Saves grid content as comma-separated values in the specified stream instance.
Declaration
procedure SaveToCSVStream(AStream: TStream; ADelimiter: char=',';
WriteTitles: Boolean=True;
VisibleColumnsOnly: Boolean=False)Arguments
AStream | Stream where the grid content is stored. |
ADelimiter | Delimiter between cell values on the same row; default is Comma (','). |
WriteTitles | Indicates that column titles are stored as the first row in the comma-separated values. False omits column titles in the output. |
VisibleColumnsOnly | Indicates if only visible columns are included in the CSV output. |
Description
SaveToCSVStream is a method used to save values in the grid as
comma-separated values in the specified stream instance.
AStream is the TStream instance where the grid content is written
in the method.
ADelimiter is the character used as the delimiter between cell
values on each row. The default value is ',' (Comma)(Decimal 44), but can be
changed to another value if needed.
WriteTitles indicates whether column titles are written at the
beginning of the stream. When set to
True, column headers are
included in the output. If the Columns collection has been enabled, the
titles are read from the TGridColumn instances in the collection. If Columns
has not been enabled, the cells in the FixedRows are written. When set to
False, titles are omitted from the values output to the stream. The
default value for the property is
True.
VisibleColumnsOnly indicates whether the CSV output contains only
visible columns on the grid. This capability is enabled when the Columns
collection is used to defined the columns and their visibility. When set to
True, any TGridColumn instance with its Visible property set to
True is included in the output.
If Columns has not been enabled, all of the columns are by default visible and written to the stream - regardless of the value in the argument. The default value for the argument is False, and allows all columns to be written to the output stream.
SaveToCSVStream processes values in the grid in row order. Each column included in the output is written using the value in ADelimiter to separate the adjacent column values. A column value is enclosed by quote characters if its content contains whitespace or the delimiter character defined in ADelimiter. Each row is terminated with the end-of-line sequence used in the LCL platform.
No actions are performed in the method if either RowCount or ColCount are set to 0.
Please note: the stream position in AStream is not changed after values are written to the stream. It is positioned at the end of the stream. Use the Seek method or the Position property in AStream to change the stream position when needed.
Use SaveToCSVFile to save the grid content as comma-separated values to a given file name.
Use LoadFromCSVStream or LoadFromCSVFile to load the content in the grid control from comma-separated values in a stream or file.
See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
