GetData

From OriginLab Wiki

(Difference between revisions)(Link to this page as [[OriginCOM:Worksheet-GetData]])
Jump to: navigation, search
Revision as of 21:28, 14 July 2008 (edit)
Cieland (Talk | contribs)
(C# Get Numeric Data from Origin)
← Previous diff
Revision as of 10:02, 20 August 2008 (edit) (undo)
Uploader (Talk | contribs)

Next diff →
Line 1: Line 1:
{{DISPLAYTITLE:GetData}} {{DISPLAYTITLE:GetData}}
 +[[category:PM]]
==Description== ==Description==
Line 9: Line 10:
</pre></code> </pre></code>
<code><pre> <code><pre>
-C++: Variant GetData(Variant nRowStart, Variant nColStart, Variant nRowEnd, Variant nColEnd, Variant format )+C++: _variant_t GetData(_variant_t nRowStart, _variant_t nColStart, _variant_t nRowEnd, _variant_t nColEnd, _variant_t format )
</pre></code> </pre></code>
<code><pre> <code><pre>
-C#: Variant GetData(Variant nRowStart, Variant nColStart, Variant nRowEnd, Variant nColEnd, Variant format )+C#: var GetData(var nRowStart, var nColStart, var nRowEnd, var nColEnd, var format )
</pre></code> </pre></code>

Revision as of 10:02, 20 August 2008


Contents

Description

Syntax

VB: Function GetData([ nRowStart As ByVal Object ], [ nColStart As ByVal Object ], [ nRowEnd As ByVal Object ], [ nColEnd As ByVal Object ], [ format As ByVal Object ] ) As Object
C++: _variant_t GetData(_variant_t nRowStart, _variant_t nColStart, _variant_t nRowEnd, _variant_t nColEnd, _variant_t format )
C#: var GetData(var nRowStart, var nColStart, var nRowEnd, var nColEnd, var format )

Parameters

nRowStart
Starting (zero based) row index to get data from. This is optional argument, defaults to 0.
nColStart
Starting (zero based) column index to get data from. This is optional argument, defaults to 0.
nRowEnd
Ending (zero based) row index to get data from. This is optional argument, defaults to -1 (to the rest of worksheet).
nColEnd
Ending (zero based) column index to get data from. This is optional argument, defaults to -1 (to the rest of worksheet).
format
one of the ARRAYDATAFORMAT enumeration, please use only the 2D ones. For example ARRAY2D_NUMERIC.

Return

Array as a variant. Actual array type is dependent on the format argument.

Remark

Examples

VBA Get Numeric Data from Origin

Run Origin first. The example will connect to Origin and load a relevant opj file, which was saved by Worksheet.SetData Examples. We'll get these numeric data in ARRAY2D_NUMERIC format from Origin, and then search for some data in the data array we got. If found, we'll print the index of the data to Excel sheet.

Public Sub getData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim Data As Variant
    Dim ii As Integer
 
    Set app = New Origin.ApplicationSI     'Connect to the running Origin
    app.Load (app.Path(APPPATH_USER) + "COMServerExamples_WN.opj")     'Load the opj file saved by relevant SetData example
    Set Wks = app.FindWorksheet("[Book1]Sheet1")
 
    'Get data as Numeric.
    Data = Wks.getData(0, 0, -1, -1, ARRAY2D_NUMERIC)
    'Search for data
    For ii = 1 To UBound(Data)
        If Data(ii, 1) = (63 * 0.01 - 1.23) Then Range("A1") = ii
        If Data(ii, 2) = (29 / 12.8 - 0.75) Then Range("A2") = ii
        If Data(ii, 3) = (41 + 0.123) Then Range("A3") = ii
    Next
 
End Sub

VBA Get Text from Origin

Run Origin first. The example will connect to Origin and load a relevant opj file, which was saved by Worksheet.SetData Examples. We'll get these Text in ARRAY2D_TEXT format from Origin, and then search for some data in the data array we got. If found, we'll print the index of the data to Excel sheet.

Public Sub getData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim Data As Variant
    Dim ii As Integer
 
    Set app = New Origin.ApplicationSI     'Connect to the running Origin
    app.Load (app.Path(APPPATH_USER) + "COMServerExamples_WT.opj")     'Load the opj file saved by relevant SetData example
    Set Wks = app.FindWorksheet("[Book1]Sheet1")
 
    'Get data as Text.
    Data = Wks.getData(0, 0, -1, -1, ARRAY2D_TEXT)
    'Search for data
    For ii = 1 To UBound(Data)
        If Data(ii, 1) = "abc 11" Then Range("A1") = ii
        If Data(ii, 2) = "def 89" Then Range("A2") = ii
    Next
 
End Sub

C# Get Numeric Data from Origin

Using Origin;
static void GetData()
{
    Origin.ApplicationSI app = new Origin.ApplicationSI();     //Connect to the running Origin
    app.Load(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_WN.opj", 0);     //Load the opj file saved by relevant SetData example
    Worksheet wks = app.FindWorksheet("[Book1]Sheet1");
 
    //Get data as Numeric.
    object Data = wks.GetData(0, 0, -1, -1, ARRAYDATAFORMAT.ARRAY2D_NUMERIC);
    double[,] result = Data as double[,];                    //Cast object to double type array. Cast to other type if needed.
    for (int ii = 1; ii <= result.GetUpperBound(0); ii++)
    {
        if (result[ii, 1] == (double)(63 * 0.01 - 1.23))
        {
            Console.WriteLine(ii + "\n");
        }
        if (result[ii, 2] == (double)(29 / 12.8 - 0.75))
        {
            Console.WriteLine(ii + "\n");
        }
        if (result[ii, 3] == (double)(41 + 0.123))
        {
            Console.WriteLine(ii + "\n");
        }
    }
 
    Console.ReadLine();
}

C# Get Text from Origin

Using Origin;
static void GetData()
{
    Origin.ApplicationSI app = new Origin.ApplicationSI();     //Connect to the running Origin
    app.Load(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_WT.opj", 0);     //Load the opj file saved by relevant SetData example
    Worksheet wks = app.FindWorksheet("[Book1]Sheet1");
 
    //Get data as Numeric.
    object Data = wks.GetData(0, 0, -1, -1, ARRAYDATAFORMAT.ARRAY2D_TEXT);
    object[,] result = Data as object[,];                    //Cast object to object type array. Cast to other type if needed.
    for (int ii = 1; ii <= result.GetUpperBound(0); ii++)
    {
        if (string.Equals(result[ii, 1],"abc 11"))
        {
            Console.WriteLine(ii + "\n");
        }
        if (string.Equals(result[ii, 2], "def 89"))
        {
            Console.WriteLine(ii + "\n");
        }
    }
 
    Console.ReadLine();
}

Version Information

8.0SR2

See Also

SetData | Application.PutWorksheet | Application.GetWorksheet | Column.SetData | Column.GetData