2.7.29 impCSV

Menu Information

Data: Import from File: Comma Delimited (CSV)


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

File Import Add Menu.png

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.

Brief Information

Import CSV file

Command Line Usage

impCSV fname:=system.path.program$+"Samples\Import and Export\donations.csv"; //import a csv file without open the dialog

X-Function Execution Options

Please refer to the page for additional option switches when accessing the x-function from script

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.

Header Info trheader

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)
Please see this page for more details.

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.
long name and units are read from metadata

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.HeaderLines.SubHeaderLines:=2  //set number of subheader as 2
 options.HeaderLines.LongNames:=1 //put 1st line of subheader to column long name
 options.HeaderLines.Units:=2 //put 2nd line of subheader to column units
 options.partial.Partial:=2 //partial import from 2nd file on.
 options.partial.FirstCol:=2; //partial import from 2nd column on

Related X-Functions

impFile, impinfo