2.1.42 PutWorksheet


Description

Put two dimensional data into a specified Origin worksheet starting at a specified column and row.

Syntax

VB: Function PutWorksheet(Name As ByVal String, data As ByVal Object, [ r1 As ByVal Object ], [ c1 As ByVal Object ] ) As Boolean
C++: bool PutWorksheet(LPCSTR Name, _variant_t data, _variant_t r1, _variant_t c1 )
C#: bool PutWorksheet(string Name, var data, var r1, var c1 )

Parameters

Name
Name of Origin worksheet to receive the data.
data
A two-dimensional safearray containing the data that will be put into the worksheet.
r1
Zero based index of the first row, in the worksheet, to receive the data. Default is zero. Use -1 to append the data.
c1
Zero based index of the first column, in the worksheet, to receive the data. Default is zero. Use -1 to append the data.

Return

Returns true if successful else false.

Remark

Examples

VBA

Public Sub PutWorksheet()
    Dim app As Origin.ApplicationSI
    Dim pws As Boolean
    Dim ii As Integer
    Dim data(1 To 100, 1 To 2) As Double
    For ii = 1 To 100
        data(ii, 1) = ii + 0.12
        data(ii, 2) = ii * 10
    Next

    Set app = New Origin.ApplicationSI

    pws = app.PutWorksheet("[Book1]Sheet1", data)
    If Not pws Then
        MsgBox ("Failed to put worksheet")
    Else
        MsgBox ("put worksheet successfully")
    End If

End Sub

C#

using Origin;
static bool TestPutWorksheet()
{
	Origin.ApplicationSI originApp = new Origin.ApplicationSI();
	Random rnd = new Random();

	int nNumRows = 100;
	int nNumCols = 2;

	// Create some data to put into the worksheet.
	double[,] data = new double[nNumRows, nNumCols];
	for (int nRow = 0; nRow < nNumRows; nRow++)
	{
		data[nRow, 0] = (double)(nRow + 1);
		data[nRow, 1] = rnd.NextDouble();
	}

	// Start a new Origin project.
	originApp.NewProject();

	// Create a new workbook.
	WorksheetPage wpg = originApp.WorksheetPages.Add("origin", System.Type.Missing);

	// Get the first worksheet in the new book.
	Worksheet wks = wpg.Layers[0] as Worksheet;
	wks.Rows = nNumRows;
	wks.Cols = nNumCols;

	// Construct a full sheet name to pass to PutWorksheet.
	string strFullSheetName = "[" + wpg.Name + "]" + wks.Name;

	// Put the data into the worksheet.
	return originApp.PutWorksheet(strFullSheetName, data, 0, 0);
}

Python

import OriginExt as O
app = O.Application(); app.Visible = app.MAINWND_SHOW
pageName = app.CreatePage(app.OPT_WORKSHEET)
testData = [[5,87,90], [3.14, 24.6, 68.09]]
app.PutWorksheet(pageName, testData)
outputData = app.GetWorksheet(pageName)
print(outputData)


import random
import win32com.client # COM module

# Connect to Origin
origin = win32com.client.Dispatch("Origin.ApplicationSI")

# Create a new workbook named "Python" using the "origin" template
pageName = origin.CreatePage(2, "Python", "origin")

# Generate X data to be the even numbers from zero to 100.
# Note:  the end of range is exclusive
xData = range(0,101,2)

# Generate Y data to be random numbers
yData = []
for i in range(0,len(xData)):
    yData.append(random.random())

# Put the X and Y data into the worksheet
origin.PutWorksheet(pageName, xData, 0, 0) # row 0, col 0
origin.PutWorksheet(pageName, yData, 0, 1) # row 0, col 1

Version Information

8.0SR2

See Also

GetWorksheet | Worksheet.SetData | Worksheet.GetData | Column.SetData | Column.GetData