2.5.20 SetData


Description

Put an array of values to a column object.

Syntax

VB: Function SetData(data As ByVal Object, [ nOffset As ByVal Object ] ) As Boolean
C++: bool SetData(_variant_t data, _variant_t nOffset )
C#: bool SetData(var data, var nOffset )

Parameters

data
The 1D array of data to be set into the column.
nOffset
Starting row index. Default is zero, the first row. If set to -1 then data is appended to the end of the column.

Return

A boolean value with true indicating set data successfully and false indicating it is failed.

Remark

Examples

Please run an Origin project firstly, and active a worksheet with property number of columns to receive the data. The examples will connect to the running Origin, and you will see the result of the examples in Origin.

You can also refer DataFormat for sending and getting different types of data array to Origin column.

VB

to Send Integer values to Origin Set Origin columns' data format as DF_CHAR, DF_LONG, DF_BYTE and DF_USHORT, and then send property Integer data to these columns. Finally, save the data as an opj file in the Origin User folder.

Public Sub SetData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim s1Data(1 To 100) As Integer
    Dim s4Data(1 To 100) As Long
    Dim u1Data(1 To 100) As Byte
    Dim u2Data(1 To 100) As Long
    Dim ii As Integer
    For ii = 1 To 100
        s1Data(ii) = ii - 10
        s4Data(ii) = ii * 100 - 1000
        u1Data(ii) = ii
        u2Data(ii) = ii * 10
    Next
 
    Set app = New Origin.ApplicationSI     'Connect to the running Origin
    Set Wks = app.FindWorksheet("")        'Select the active worksheet
 
    'Send Integer (1 byte) values to Origin
    Wks.Columns(0).DataFormat = DF_CHAR
    Wks.Columns(0).SetData (s1Data)
    'Send Integer (4 bytes) values to Origin
    Wks.Columns(1).DataFormat = DF_LONG
    Wks.Columns(1).SetData (s4Data)
    'Send Integer (unsigned 1 byte) values to Origin
    Wks.Columns(2).DataFormat = DF_BYTE
    Wks.Columns(2).SetData (u1Data)
    'Send Integer (unsigned 2 bytes) values to Origin
    Wks.Columns(3).DataFormat = DF_USHORT
    Wks.Columns(3).SetData (u2Data)

    'Save the project to Origin User folder
    app.Save (app.Path(APPPATH_USER) + "COMServerExamples_CI.opj")
 
End Sub

to Send Floating-point values to Origin Set Origin columns' data format as DF_FLOAT and DF_DOUBLE, and then send property Floating-point data to these columns. Finally, save the data as an opj file in the Origin User folder.

Public Sub SetData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim f4Data(1 To 100) As Single
    Dim d8Data(1 To 100) As Double
    Dim ii As Integer
    For ii = 1 To 100
        f4Data(ii) = ii * 0.01 - 1.23
        d8Data(ii) = ii / 12.8 - 0.75
    Next
 
    Set app = New Origin.ApplicationSI
    Set Wks = app.FindWorksheet("")
 
    'Send Numeric (float 4 bytes) values to Origin
    Wks.Columns(0).DataFormat = DF_FLOAT
    Wks.Columns(0).SetData (f4Data)
    'Send Numeric (double 8 bytes) values to Origin
    Wks.Columns(1).DataFormat = DF_DOUBLE
    Wks.Columns(1).SetData (d8Data)

    'Save the project to Origin User folder
    app.Save (app.Path(APPPATH_USER) + "COMServerExamples_CF.opj")
 
End Sub

to Send Complex values(1D Array) to Origin Set the Origin column's data format as DF_COMPLEX, and then send complex values via 1D double array to the column. Finally, save the data as an opj file in the Origin User folder.

When sending complex as 1D array, the size of the array must be twice the number of values and each must be packaged with the first double value being the real part and the next being the corresponding imaginary part.

Public Sub SetData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim dData(1 To 100) As Double 'allocate twice the needed size
    Dim ii As Integer
    
    For ii = 1 To 50
        dData(ii * 2 - 1) = ii  'real
        dData(ii * 2) = ii * 0.1 'imaginary
    Next
 
    Set app = New Origin.ApplicationSI
    Set Wks = app.FindWorksheet("")
 
    'Send Complex (16 bytes) values to Origin
    Wks.Columns(0).DataFormat = DF_COMPLEX
    Wks.Columns(0).SetData (dData)

    'Save the project to Origin User folder
    app.Save (app.Path(APPPATH_USER) + "COMServerExamples_CC1.opj")
 
End Sub

to Send Complex values(2D Array) to Origin Set the Origin column's data format as DF_COMPLEX, and then send 2D DOUBLE data array to the column. Finally, save the data as an opj file in the Origin User folder.

When send 2D array, Origin simply take the first column as real and the 2nd column as imaginary.

Public Sub SetData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim dData(1 To 50, 1 To 2) As Double 'using 2D array
    Dim ii As Integer
    
    For ii = 1 To 50
        dData(ii, 1) = ii  'real
        dData(ii, 2) = ii * 0.1 'imaginary
    Next
 
    Set app = New Origin.ApplicationSI
    Set Wks = app.FindWorksheet("")
 
    'Send Complex (16 bytes) values to Origin, use col(2) so you can send
    'both 1D (col(1) in that example) and 2D to compare
    Wks.Columns(1).DataFormat = DF_COMPLEX
    Wks.Columns(1).SetData (dData)
    
    'Save the project to Origin User folder
    app.Save (app.Path(APPPATH_USER) + "COMServerExamples_CC2.opj") 
End Sub

to Send Text to Origin Set the Origin column's data format as DF_TEXT, and then send property string array to the column. Finally, save the data as an opj file in the Origin User folder.

Public Sub SetData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim tData(1 To 100) As String
    Dim ii As Integer
    For ii = 1 To 100
        tData(ii) = "abc" + Str(ii)
    Next
 
    Set app = New Origin.ApplicationSI
    Set Wks = app.FindWorksheet("")
 
    'Send Text (String Array) to Origin
    Wks.Columns(0).DataFormat = DF_TEXT
    Wks.Columns(0).SetData (tData)

    'Save the project to Origin User folder
    app.Save (app.Path(APPPATH_USER) + "COMServerExamples_CC1.opj")
 
End Sub

C#

to Send Integer values to Origin

using Origin;
static void SetData()
{
    byte[] u1Data = new byte[100];
    sbyte[] s1Data = new sbyte[100];
    ushort[] u2Data = new ushort[100];
    for (int ii = 0; ii < 100; ii++)
    {
        u1Data[ii] = (byte)(ii * 2);
        s1Data[ii] = (sbyte)(ii - 10);
        u2Data[ii] = (ushort)(ii * 123);
    }

    Origin.ApplicationSI app = new Origin.ApplicationSI();     //Connect to the running Origin
    Worksheet wks = app.FindWorksheet("");                     //Select the active worksheet

    //Send Unsigned 1 byte Integers to Origin
    wks.Columns[0].DataFormat = COLDATAFORMAT.DF_BYTE;
    wks.Columns[0].SetData(u1Data, 0);
    //Send Sigend 1 byte Integers to Origin
    wks.Columns[1].DataFormat = COLDATAFORMAT.DF_CHAR;
    wks.Columns[1].SetData(s1Data, 0);
    //Send Unsigned 2 bytes Integers to Origin
    wks.Columns[2].DataFormat = COLDATAFORMAT.DF_USHORT;
    wks.Columns[2].SetData(u2Data, 0);

    //Save the project to Origin User folder
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_CI.opj");

}

to Send Floating-point values to Origin

using Origin;
static void SetData()
{
    float[] f4Data = new float[100];
    double[] d8Data = new double[100];
    for (int ii = 0; ii < 100; ii++)
    {
        f4Data[ii] = (float)(ii * 0.01 - 1.23);
        d8Data[ii] = ii / 12.8 - 0.75;
    }

    Origin.ApplicationSI app = new Origin.ApplicationSI();
    Worksheet wks = app.FindWorksheet("");

    //Send Numeric (float 4 bytes) values to Origin
    wks.Columns[0].DataFormat = COLDATAFORMAT.DF_FLOAT;
    wks.Columns[0].SetData(f4Data, 0);
    //Send Numeric (double 8 bytes) values to Origin
    wks.Columns[1].DataFormat = COLDATAFORMAT.DF_DOUBLE;
    wks.Columns[1].SetData(d8Data, 0);

    //Save the project to Origin User folder
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_CF.opj");

}

to Send Complex values(1D Array) to Origin

Using Origin;
static void SetData()
{
    double[] dData = new double[100];
    for (int ii = 0; ii < 50; ii++)
    {
        dData[ii * 2] = ii;     //real
        dData[ii * 2 + 1] = ii * 0.1;     //imaginary
    }

    Origin.ApplicationSI app = new Origin.ApplicationSI();
    Worksheet wks = app.FindWorksheet("");

    //Send Complex (16 bytes) values to Origin
    wks.Columns[0].DataFormat = COLDATAFORMAT.DF_COMPLEX;
    wks.Columns[0].SetData(dData, 0);

    //Save the project to Origin User folder
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_CC1.opj");

}

to Send Complex values(2D Array) to Origin

Using Origin;
static void SetData()
{
    double[,] dData = new double[100, 2];
    for (int ii = 0; ii < 100; ii++)
    {
        dData[ii, 0] = ii;     //real
        dData[ii, 1] = ii * 0.1;     //imaginary
    }

    Origin.ApplicationSI app = new Origin.ApplicationSI();
    Worksheet wks = app.FindWorksheet("");

    //Send Complex (16 bytes) values to Origin
    wks.Columns[0].DataFormat = COLDATAFORMAT.DF_COMPLEX;
    wks.Columns[0].SetData(dData, 0);

    //Save the project to Origin User folder
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_CC2.opj");

}

to Send Text to Origin

Using Origin;
static void SetData()
{
    string[] tData = new string[100];
    for (int ii = 0; ii < 100; ii++)
    {
        tData[ii] = "abc" + ii.ToString();
    }

    Origin.ApplicationSI app = new Origin.ApplicationSI();
    Worksheet wks = app.FindWorksheet("");

    //Send Text (String Array) to Origin
    wks.Columns[0].DataFormat = COLDATAFORMAT.DF_TEXT;
    wks.Columns[0].SetData(tData, 0);

    //Save the project to Origin User folder
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_CT.opj");

}

Version Information

8.0SR2

See Also

GetData | DataFormat | Application.PutWorksheet | Application.GetWorksheet | Worksheet.SetData | Worksheet.GetData