CSV data context
CSV data contexts allow exposing one or more CSV files as tables. To add a CSV data context to your project, use the context menu command as shown below.
This will create a new data context script and scaffold code for a custom CSV data context class. To register CSV files as tables, you must implement the
1 2 3 4 5 6 7 8
The arguments of the
AddFile method are:
pathto the CSV file
nameof the table (optional, if not specified, file name is used)
After running the script, two tables will be exposed by the data context. These tables can then be used by both scripts and other project code.
By default, the data type for all columns is
string. This can be overridden by using the
1 2 3 4 5 6 7 8 9 10 11 12
Once the script is executed, the data context will be updated to use the specified column types.
Using relative paths
In workbook apps, you can look up the current workbook path in order to use csv files that are in the same directory as the workbook.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Combining with workbook data
In workbook apps, you might want to use both the workbook data context as well as a CSV data context to access data in External CSV files. This is enabled out of the box as context definition scripts will add the types they generate into the
DataContextTypes list in the
project.config file without removing the types generated by other scripts.