ExportToCSV
Exports an array’s content to a CSV/TSV file.
Syntax
expression.ExportToCSV
(csvArray, [pconfig:= Nothing
], [PassControlToOS:= True
], [enableDelimiterGuessing:= True
], [EnforcedQuotation:= False
])
Parameters
Part | Description |
---|---|
csvArray | Required. Identifier specifying a Variant Type variable which represents the data to be written to a CSV file. |
pconfig | Optional. Identifier specifying a CSVparserConfig object variable. |
PassControlToOS | Optional. Identifier specifying a Boolean Type variable. Use this to prevent the application from appearing to hang at runtime. |
enableDelimitersSniffing | Optional. Identifier specifying a Boolean Type variable. |
EnforcedQuotation | Optional. Identifier specifying a Boolean Type variable. |
Returns value
None
📝Note
The csvArray parameter can be an
CSVArrayList
or an array (one-dimensional, two-dimensional or jagged) variable, passing another type of variable will cause an error.
- See also
- ParseConfig Property, CSVArrayList class.
Behavior
When the pconfig
parameter is omitted, the parser will use the ParseConfig
property as the configuration object. If the file specified in the .path
configuration property already exists and has some content, the parser will try to guess the delimiters and the data will be added to the file when the enableDelimitersSniffing
is set to True
. Setting the EnforcedQuotation
parameter to True
will force to quote all fields in the created CSV file.
⚠️Caution
Fields containing literal escape characters will be escaped using the classic escape sequence (duplicating each escape character) or using the Unix escape sequence. The behavior will be controlled by the
.dialect.escapeMode
property of the given configuration object.
☕Example
Sub ExportToTSV()
Dim CSVint As CSVinterface
Dim conf As CSVparserConfig
Set CSVint = New CSVinterface
Set conf = CSVint.parseConfig
With conf
.path = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
.dynamicTyping = False
Set .dialect = CSVint.SniffDelimiters(conf) 'Try to guess CSV file data delimiters
CSVint.ImportFromCSV conf 'Import the data
.path = Environ("USERPROFILE") & "\Desktop\Demo_100000records.tsv"
.dialect.fieldsDelimiter = vbTab
CSVint.ExportToCSV CSVint.items, conf 'Export internal items to a TSV file
End With
Set CSVint = Nothing 'Terminate the current instance
End Sub