SetData

From OriginLab Wiki

(Difference between revisions)(Link to this page as [[OriginCOM:Worksheet-SetData]])
Jump to: navigation, search
Revision as of 19:49, 3 July 2008 (edit)
Cieland (Talk | contribs)
(C# to Send Text to Origin)
← Previous diff
Revision as of 10:02, 20 August 2008 (edit) (undo)
Uploader (Talk | contribs)

Next diff →
Line 1: Line 1:
{{DISPLAYTITLE:SetData}} {{DISPLAYTITLE:SetData}}
 +[[category:PM]]
==Description== ==Description==
Line 9: Line 10:
</pre></code> </pre></code>
<code><pre> <code><pre>
-C++: bool SetData(Variant data, Variant nRowOffset, Variant nColOffset )+C++: bool SetData(_variant_t data, _variant_t nRowOffset, _variant_t nColOffset )
</pre></code> </pre></code>
<code><pre> <code><pre>
-C#: bool SetData(Variant data, Variant nRowOffset, Variant nColOffset )+C#: bool SetData(var data, var nRowOffset, var nColOffset )
</pre></code> </pre></code>

Revision as of 10:02, 20 August 2008


Contents

Description

Send 2D array to Origin. This method is the same as Application.PutWorksheet

Syntax

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

Parameters

data
Two dimensional safearray that will be put into worksheet.
nRowOffset
Starting index to set array, default is 0. If it is -1, adding new data to the end of rows.
nColOffset
Starting index to set array, default is 0. If it is -1, adding new data to the end of cols.

Return

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

Remark

Examples

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

Please refer examples at Column.SetData for more details about buffering data of different types.

VB to Send Numeric values to Origin

Public Sub SetData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim Data(1 To 100, 1 To 3) As Double
    Dim ii As Integer
    'Set the 2D numeric array, which has 100 rows and 3 cols
    For ii = 1 To 100
        Data(ii, 1) = ii * 0.01 - 1.23
        Data(ii, 2) = ii / 12.8 - 0.75
        Data(ii, 3) = ii + 0.123
    Next
 
    Set app = New Origin.ApplicationSI     'Connect to the running Origin
    Set Wks = app.FindWorksheet("")        'Select the active worksheet
 
    'Send Numeric values to Origin
    Wks.SetData (Data)
 
    'Save the project to Origin User folder
    app.Save (app.Path(APPPATH_USER) + "COMServerExamples_WN.opj")
 
End Sub

VB to Send Text to Origin

Public Sub SetData()
    Dim app As Origin.ApplicationSI
    Dim Wks As Origin.Worksheet
    Dim tData(1 To 100, 1 To 2) As String
    Dim ii As Integer
    'Set the 2D string array, which has 100 rows and 2 cols
    For ii = 1 To 100
        tData(ii, 1) = "abc" + Str(ii)
        tData(ii, 2) = "def" + Str(ii + 3)
    Next
 
    Set app = New Origin.ApplicationSI
    Set Wks = app.FindWorksheet("")
 
    'Send Text to Origin
    Wks.SetData (tData)
 
    'Save the project to Origin User folder
    app.Save (app.Path(APPPATH_USER) + "COMServerExamples_WT.opj")
 
End Sub

C# to Send Numeric values to Origin

static void SetData()
{
    float[,] Data = new float[100, 3];
    //Set the 2D numeric array, which has 100 rows and 3 cols
    for (int ii = 0; ii < 100; ii++)
    {
        Data[ii, 0] = (float)(ii * 0.01 - 1.23);
        Data[ii, 1] = (float)(ii / 12.8 - 0.75);
        Data[ii, 2] = (float)(ii + 0.123);
    }
 
    Origin.ApplicationSI app = new Origin.ApplicationSI();     //Connect to the running Origin
    Origin.Worksheet wks = app.FindWorksheet("");              //Select the active worksheet
 
    //Send Numeric values to Origin
    wks.SetData(Data, 0, 0);
 
    //Save the project to Origin User folder
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_WN.opj");
 
}

C# to Send Text to Origin

static void SetData()
{
    string[,] Data = new string[100, 2];
    //Set the 2D numeric array, which has 100 rows and 2 cols
    for (int ii = 0; ii < 100; ii++)
    {
        Data[ii, 0] = "abc" + ii.ToString();
        Data[ii, 1] = "def" + (ii + 3).ToString();
    }
 
    Origin.ApplicationSI app = new Origin.ApplicationSI();
    Origin.Worksheet wks = app.FindWorksheet("");
 
    //Send Text values to Origin
    wks.SetData(Data, 0, 0);
 
    //Save the project to Origin User folder
    app.Save(app.path(Origin.APPPATH_TYPES.APPPATH_USER) + "COMServerExamples_WT.opj");
 
}

Version Information

8.0SR2

See Also

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