# 2.7.27 impCSV

Data: Import from File: Comma Delimited (CSV)

If you do not see this file type, choose Data: Import from File: Add/Remove File Types...

 To add drag & drop support for a file type, see Import Filter Manager.

This X-Function supports file re-import. See this topic for details.

Import CSV file

 impCSV fname:=system.path.program$+"Samples\Import and Export\donations.csv"; //import a csv file without open the dialog  ## X-Function Execution Options ## Variables Display Name Variable Name I/O and Type Default Value Description File Name fname Input string fname$

Specify the filename of the file to be imported.

File Info trfiles

Input

TreeNode

<unassigned>

This is used to show the file size in the dialog. The information is detected by Origin automatically.

Import Options options

Input

TreeNode

<unassigned>

This is mainly used in the dialog, for tweaking the import options. Please see the Descriptions section for details.

Output orng

Output

Range

<active>

Use this to specify the output range. See the syntax here.

Output

TreeNode

<optional>

This is for outputting the header information. It is hidden from the GUI. Users are not advised to use this variable from Labtalk.

Repeat import reimp

Input

int

0

This is used for the reimport feature. It is hidden from the GUI. Users are not advised to use this variable from Labtalk.

## Description

CSV (comma-separated values) is one kind of delimited file, which as the name suggests, uses commas to separate values. This X-Function helps you to import this kind of file.

Details on Some Dialog Options

• Import Options(options)

## Examples

This example imports multiple CSV files into same worksheet. File names are put to column comments.
Partial import is done from 2nd file on, so only data from 2nd column on is imported.

string fname$;//all the XF that deals with files default to fname$ string
findFiles path:=system.path.program$+"Samples\Batch Processing" ext:="*.csv" addpath:=1;//find all csv files under specified path and put found file names in fname$
impCSV //import all csv files
options.Mode:=1  //set Multi-file(except 1st) import mode as 1 so new csv files are put to new columns in same sheet
options.names.FNameToSht:=0 //sheet name will not be renamed
options.names.FNameToBk:=0 //bookname will not be renamed
options.names.FNameToBkComm:=0 //nook comments will not be renamed
options.names.FNameToColComm:=1 //put file name to column comments
options.names.FPathToComm:=0 //full path will not be included when renaming book/sheet/column with filename
options.partial.FirstCol:=2; //partial import from 2nd column on