2.1.16 FindWorksheet

Description

Find a worksheet by name.

Syntax

VB: Function FindWorksheet(Name As ByVal String ) As Worksheet
C++: Worksheet FindWorksheet(LPCSTR Name )
C#: Worksheet FindWorksheet(string Name )

Parameters

Name
The range string of the Origin worksheet to be found. The range string contains the workbook name between square brackets followed by the sheet name:
[<bookName>]<sheetName>
The following special notations are also supported:
  1. Empty string -- this means the active sheet from the active book
  2. Book name only -- like "Book1", will get the active sheet from named book
  3. Sheet name only with ! at the end -- like "Sheet2!", will get the named sheet from the active book

Return

If the named worksheet is found then an Origin Worksheet is returned.

Remark

Examples

VBA

Private Sub OutputWorksheetColumnNames(sheetName As String)
    Dim app As Origin.ApplicationSI
    Set app = New Origin.ApplicationSI
 
    Dim wks As Origin.Worksheet
    Set wks = app.FindWorksheet("[Book1]Sheet1")
    If wks Is Nothing Then
        MsgBox ("Failed to find worksheet")
        Exit Sub
    End If

    Range("A1") = wks.Cols ' put number of columns in Excel cell A1

    Dim i As Long
    Dim col As Origin.Column
    Dim name As String
    For i = 1 To wks.Cols
        Set col = wks.Columns.Item(i - 1)
        If col.LongName = "" Then
            name = col.name ' use column short name
        Else
            name = col.LongName ' use column long name
        End If
        Range("B" & i) = name ' put name in Excel column B row i 
    Next i
End Sub

C#

using Origin; // allow using Column, Worksheet, etc. without having to write Origin.Column

static void OutputActiveWorksheetColumnNames()
{
    ApplicationSI app = new Origin.ApplicationSI();

    Worksheet wks = app.FindWorksheet(""); // pass empty string for active sheet
    if (wks == null)
    {
        Console.WriteLine("Failed to get active worksheet.");
        return;
    }
    Console.WriteLine("Active worksheet name is " + wks.Name);

    Column col;
    for( int i = 0; i < wks.Columns.Count; i++ )
    {
        col = wks.Columns[i];
        if (col == null)
            Console.WriteLine("Failed to get column " + i);
        else
            Console.WriteLine("Column " + i + " name is " + col.Name);
    }

    Console.ReadKey();
}

Python

import OriginExt as O
app = O.Application(); app.Visible = app.MAINWND_SHOW
pageName = app.CreatePage(app.OPT_WORKSHEET)
layer = app.FindWorksheet(pageName)
print(layer.Name)

Version Information

8.0SR2

See Also

FindMatrixSheet