Writing to File
Describes how to output a data table to a file
1. Write to file
Once you have added all the data to the OutputTable
, you can write the data to a file. The output data file is in .csv format and is stored in the solution path Output folder. After registering the data table in the OutputManager
, it can be written to a file using the WriteToFile
method.
When writing to a file, the WriteToFile
method provides the following functionality
Appending to the last line of an existing file
If a file with the same filename exists, you can append to the contents of the existing file to output data as needed without deleting the existing file. This can be accomplished by setting the value of the isAppend parameter of the WriteToFile
method to True. The example code below outputs data following the last line of an existing file.
Setting whether to add column names for the first row
When writing to a file, the default is to write the column names of the corresponding output data schema in the first row. However, you can choose not to write the column names in the first row as needed. You can accomplish this by setting the value of the isHeaderInclude parameter of the WriteToFile
method to False. The example code below prevents the column names from being written to the first row.
Setting file name
When writing to a file, it defaults to writing the file name to be the same as the output data schema name. Users can change the output file name as needed. This can be accomplished by setting the file name you want to change in the value of the name parameter of the WriteToFile
method. The example code below renames the file to "Result".
2. Example code
Last updated