Sign in Join
FPDoc Onlineexperiment

TCustomStringGrid.SaveToCSVFile procedure

Member of TCustomStringGridpublicIn unit Grids

Saves grid content as comma-separated values in the specified file name.

Declaration

pascal
procedure SaveToCSVFile(AFileName: string; ADelimiter: char=','; 
                       WriteTitles: Boolean=True; 
                       VisibleColumnsOnly: Boolean=False)

Arguments

AFileName

File name (with optional path) where CSV data is stored.

ADelimiter

Delimiter used between cell values in CSV output; default is Comma (',').

WriteTitles

Indicates if column captions are written as the first row of CSV data in the file. False omits column titles in the output.

VisibleColumnsOnly

Indicates if only visible columns are included in the CSV output.

Description

SaveToCSVFile is a method used to store the contents of the grid control as comma-separated values in the specified file name.

AFileName contains the qualified path and file name where the CSV data is stored.

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 file. 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 file. 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 file - 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 file.

SaveToCSVFile creates a temporary TFileStream instance and calls SaveToCSVStream to process rows the and columns in the grid.

Use SaveToCSVStream to save the grid content as comma-separated values to a TStream instance.

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.