Delimited files such as “.csv” or “.txt” are commonly used formats for importing or exporting data. Because delimited files can be generated and manipulated easily, more and more data published on the Web is tabular data, usually published as comma-separated values.
A good way to format this data and show it to your customers is to use 4D View Pro.
In 4D v19 R2, using the VP Import document and VP Export document commands that support delimited text file formats such as CSV, you can easily display that data for your clients.
The process is similar to importing and exporting Excel files, as described in the previous blog post: Work with .xlsx documents using 4D View Pro. You need to use the VP Import document and VP Export document commands to import or export delimited text files in 4D View Pro.
Importing A delimited text file
VP Import document supports the import of common CSV files that use a comma to separate values. The command automatically determines what sort of row delimiter is used in the file. In this case, you just need to indicate the path of the file and the cell where the data restitution begins:
$csvOptions:=New object
$csvOptions.range:=VP Cell("ViewProArea"; 5; 0)
VP IMPORT DOCUMENT("ViewProArea"; "c:\\tmp\\data.csv"; New object("csvOptions"; $csvOptions))
But all delimited text files are not CSV, so you can modify the column delimiter according to your needs. For example, if you need to import a text file with tab as value delimiter:
$csvOptions:=New object
$csvOptions.range:=VP Cell("ViewProArea"; 5; 0)
$csvOptions.columnDelimiter:=Char(9)
VP IMPORT DOCUMENT("ViewProArea"; "c:\\tmp\\export.txt"; New object("csvOptions"; $csvOptions))
exporting A delimited text file
VP Export document uses comma and “\r\n.” as default values for column delimiter and row delimiter, but you can specify your columnDelimiter and your rowDelimiter according to your needs:
$csvOptions:=New object
$csvOptions.range:=VP Cells("ViewProArea"; 5; 0; 2; 20)
$csvOptions.columnDelimiter:="|"
$csvOptions.rowDelimiter:="\n"
VP EXPORT DOCUMENT("ViewProArea"; "c:\\tmp\\data.txt"; New object("format"; vk csv format; "csvOptions"; $csvOptions))
More information is available in the doc center.