3.7.5.99 Wbk.DC


The wbk.DC object has properties and methods related to the Data Connector attached to the workbook. The workbook object can be referred to using either "wbook" or "wbk".

Properties

Property Access Description
wbk.DC.mfiles Read/write
numeric
Check if the workbook is multiple connected.
wbk.DC.nConns Read Only Returns the number of connected sheets
wbk.DC.OCFiles$ Read Only Returns the relative path of the connector cpp file to the Apps root folder. To construct the full OC file path, use

"%@A"+wbk.dc.OCFile$

wbk.DC.type$ Read Only Returns the connector type, CSV_Connector or JSON_Connector. This string can be used in wbk.DC.Add

Methods

Method Description
wbk.DC.add(file_type) Add Data Connector of file_type...

... where file_type is the name of the Connector (generally, just the name of the Connector, enclosed by double-quotes if there is a space in the name -- e.g. wbook.DC.add("Import Filter")). If in doubt, use the name of the Connector as it appears on the Connectors tab of the Apps Gallery (minus the word "Connector") and enclose file_type in double-quotes.

wbk.DC.import(nn) Import data:

nn = 0 or not specify: import all sheets in the workbook without opening the select... menu,
nn = 1: only import data for the active sheet. It will open Select... menu and then do the import.

wbk.DC.newsheet(sheet$) Connect to another sheet.
wbk.DC.remove(nn) Remove data connector.

nn = 0: Default value when nn is not specified. Remove data connector object from the current workbook, and remove edit protection from all destination sheets in this workbook.
nn = 1: Disconnect data source from the current worksheet and remove its edit protection.
nn = 2: Remove only eidt protection from the current worksheet, but connection will be kept.

Examples

Below codes import a HTML table on a wiki webpage to Origin worksheet.

newbook;
wbook.dc.add("HTML");
urllink$="https://en.wikipedia.org/wiki/List_of_metropolitan_statistical_areas";
wks.dc.source$={"isAdv":0,"bas":{"url":"%(urllink$)"},"adv":{"urlParts":["",""],"cmdTimeout":"","hdrParams":[]}};
wks.DC.Sel$=Tables/_1;
wks.dc.import();

The following example shows how to import an Excel file by Data Connector.

newbook;
wbook.dc.add("Excel");
wks.dc.source$=System.path.program$+"Samples\Import and Export\United States Energy (1980-2013).xls";
wks.dc.sel$="Natural Gas";
wks.dc.import();
//set column label rows
worksheet -s 0 1 0 1; 
wks.setaslabel(C, -1, 0, 0);
wks.setaslabel(L, -1, 0, 0);
wks.setaslabel(U, -1, 0, 0);

This example uses the Origin Connector to import data from another Origin project by running a query (information on the SQL-like query language supported by the Origin Connector can be found here).

// Origin project file location:
string path$ = "C:\temp\mydata.opju";
// Create new workbook in current project
newbook;
// Connect to the desired Origin project using the Origin Data Connector
wbook.dc.ADD("Origin");
wks.dc.source$ = path$;
// Specify query string to pull all X columns that have long name of "alpha"
wks.dc.sel$=Select Column from Project where (Column_LName like "alpha" AND Column_Type = X);
wks.dc.import();
//This example uses the NetCDF Connector to do partial import of web-stored multi-dimensional data in a .nc file
newbook mat:=1;
wbk.dc.add("NetCDF");
wks.dc.source$="https://psl.noaa.gov/thredds/fileServer/Datasets/cpc_us_precip/precip.V1.0.mon.mean.nc";
// import z=1 to end, read 1 skip 11; lon shift, lat flip, formula v*0.0393701
wks.dc.sel$=NetCDF/precip[1:0|1-11][y#][x/2]v*0.0393701;
wks.dc.import();

The following example shows how to specify an import filter in the same folder as your data file.

wbook.dc.add("Import Filter");
wks.dc.source$="C:\2016\Samples\Import and Export\S15-125-03.dat"; // connect to .dat file
wks.dc.sel$="test1.oif"; //use import filter "test1.oif" in the data folder - see Note
wks.dc.import();

Note: You can refer to an import filter saved to UFF\Filters using the %Y string register as in, for example, wks.dc.sel$="%YFilters\test1.oif";

This example can import Excel file with two sheets and setting headings

string fname$=system.path.program$ + "Samples\Import and Export\United States Energy (1980-2013).xls";
wbook.dc.add("Excel");
wks.dc.source$ = fname$;
Tree tr1 = wks.dc.Optn$;
tr1.Settings.mainheader = 2;
tr1.Settings.labels.SetAttribute("Use",1);
tr1.Settings.labels.longname=1;
tr1.Settings.labels.unit=2;
tr1.tostring(wks.dc.optn$);
wks.dc.sel$ = "Oil";
wks.dc.import();
//now connect to another sheet named "Coal"
wbook.dc.Newsheet("Coal");

See Also

Wks, Wks.DC