3.7.5.105 Wks.DC

Data Connector added to a worksheet are handled as objects in Origin. The column attributes can be accessed and changed using the properties in the table below.

Note:

For workbook level controls of Data Connector, please refer to Wbk object.

Properties

Property Access Description
wks.DC.auto Read/write
numeric
Set/Get auto import status
wks.DC.c1
wks.DC.c2
Read/write
numeric
Range of columns imported: c1 is the beginning column and c2 is the ending column.
wks.DC.cntrl Read/write
numeric
Origin 2024b Import option.
wks.DC.Flags Read/write
numeric
Append data rows in imported file to active worksheet. As of Origin 2021, for Data Connector = Text/CSV only
wks.DC.Ignore Read/Write
numeric
Ignore Data Connector icon. 0 = Data Connector icon is usable, 1 = Data Connector icon is neither selectable nor usable.
wks.DC.optn$ Read/write
string
Get or set connector settings as a string. Supported only for CSV, Excel etc connector types using its own GetN dialog.
wks.DC.Path$ Read/Write
string
Absolute path of Connector Data Source, both for local files and for web data as long as the local cache has not expired or been cleared.
wks.DC.Script$ Read/Write
string
Get or set Post Import Scripts.
wks.DC.Sel$ Read/Write
string
Specify the selection of sheets/table inside the data source. Use for file formats such as NetCDF or TDMS.
wks.DC.Source$ Read/write
string
Relative path of data source.
wks.DC.Sstatus Read Only Source Status
wks.DC.SType Read/write
numeric
Data source type.
wks.DC.Valid Read/write
numeric
Check the status of Data Connector added to the worksheet

Methods

Method Access Description
wks.DC.Add(sel$) Read/write
numeric
Add selected table sel$ to active sheet.
wks.DC.Allow() Read/write
numeric
Check if the worksheet is used as the destination of a Data Connector.
wks.DC.Import() Read/write
numeric
Import data into current sheet, without opening the Import Options dialog.
wks.DC.Reset() Read/write
numeric
Clear imported data. The connection will remain.

Examples

EX1

//This example shows how to import a CSV file by Data Connector
newbook;
wbook.dc.add("CSV");
wks.dc.source$=System.path.program$+"Samples\Batch Processing\T275K.csv";
wks.dc.import();

EX2

// This example shows how to import multiple CSV files into one worksheet appending by rows
newbook;
string fname, path$=system.path.program$ + "Samples\Batch Processing\"; 
findfiles fname:=fname$ ext:="*.csv";

int num = fname.GetNumTokens(CRLF);
wbook.dc.add("CSV");
loop(ii,1,num)
{
next$ = fname.GetToken(ii, CRLF)$;
if (ii==1)
{
	wks.dc.flags=256;	// turn on append rows mode
}
wks.dc.source$=next$;
Tree tr1=wks.dc.optn$;
tr1.settings.partial.SetAttribute("Use", 1);
tr1.settings.partial.row$="2"; // import 2nd row for each file
tr1.ToString(wks.dc.optn$);
wks.dc.import();
}