The WKS object has properties and methods related to an Origin sheet (Note: A sheet can be either Worksheet or Matrix Sheet). You can use range notation to define a worksheet object:

range wksObject = [winName]sheetName!

If no range is specified, Origin will work on the active sheet. Once a worksheet (matrix sheet) object is defined, the object properties and methods can be accessed using the following syntax:


For example:

range rWa = [Book2]Sheet2!;     // Define a worksheet object range
rWa.colSel(2,1);                // Select the second column of that sheet
rWa.vGrids = 0;                 // Turn off vertical grid lines
range rWb = !;                  // Use the active worksheet as a range
rWb.AddCol(NewColumn);          // Add a new column
NumColumns = rWb.ncols;         // Find out how many columns

Please see the wproperties X-Function for Read/Write access to additional Worksheet properties. What's more, there are some X-Function can do the same things as wks object. For more information, please refer to worksheet manipulation X-Functions.


When operating on the active worksheet or matrix sheet, you can use wks.property to access sheet properties; otherwise, range notation should be used.

Property Access Description

(8.0 SR0)

Auto add rows when sheet is resized.


range aa=[book1]sheet2!;
// Disable auto add rows to maintain fixed 
// number of rows and columns
// Setup the wks with 3x2
aa.nCols = 2;aa.nRows = 3;
wks.c1, c2, r1, r2 Read only
Selection range. First and last columns and rows.
wks.cNamen$ Read only
The nth worksheet column short name. See wks.cnamemode to operate on specific column types. (See also: Wks.Col (Object))
wks.cNameMode Read/write
Its value determines the columns that wks.cnamen$ operates on. Set wks.cnamemode to the following values: 0 = all columns, 1 = numeric columns, 2 = text columns, 4 = text and numeric (mixed) columns, and 64 = columns in the selection range. Set wks.cnamemode = 128 to return the full dataset name to wks.cnamen$.
wks.col Read/write
Current column. See also: The Wks.Col object properties.
wks.colWidth Read/write
Column width. example:

Or use the wcolwidth X-Function to update column width.

wks.epd Read/write
specify if exclude current worksheet when do plotting with Layer Contents and Plot Setup etc graphing related dialogs. 1= tag this sheet as Exclude from plotting dialog; 0 = relief the exclude tag.

You use the system variable @TCE to indicate the tagged(excluded) sheet name with desired color, such as @TCE=Color(255, 60, 60);.

wks.export Read/write
Worksheet export settings; enter wks.export.= for sub-methods.
wks.font Read/write
Font (by index) of the Standard name style in the sheet. You can use the font(name) function to get a font's index, like wks.font = font(Courier New);
wks.fSize Read/write
Font size of the Standard name style in the sheet, like wks.fsize = 12;

(2019b SR0)

Read only
Return whether the workbook/worksheet has a Data Connector:

0 = workbook doesn't have Data Connector,
1 = worksheet is used by a Data Connector as the output (destination sheet),
2 = worksheet is not used by any Data Connector as the output. Iin this case, the worksheet may contain a Data Connector but doesn't build a valid connection. To check if the worksheet is used by a Data Connector as output or not, use "wks.DCValid".

Display horizontal and vertical grid: 1 = enable, 0 = disable.

(2019 SR0)

Read Only
Return the number of hidden rows in the worksheet. wks.hiddenRows == wks.maxRows - wks.visibleRows.

(9.1 SR0)

Read Only
Read whether the worksheet is hierarchical (i.e. contains collapsible nodes and tables such as an analysis report sheet does) or not: 1=hierarchical, 0=flat sheet.
wks.ignorehidden Read/write
Treatment of hidden rows in plotting and analysis operations:

0 = Include data in hidden rows on plotting and analysis.
1 = (default) Ignore hidden rows on plotting and analysis.

wks.import Read/write
Worksheet import settings; enter wks.import.= for sub-methods.
wks.index Read/write
Worksheet index in workbook, i.e. 1,2,3, etc.

Use this property to reorder worksheets. For example:

newbook sheet:=4; // Create a 4 sheets workbook;
wks.index = 3; // Move "Sheet1" to the 3nd worksheet;

Note: This property is Read Only before 8.5.0 SR1.

wks.joinMode Read/write
Set/get the worksheet join mode. Values may be the following:

0 = enumerate when column names match. Append when matching rows are not found.

1 = drop when column names match. Append when matching rows are not found.

2 = enumerate when column names match. Drop when matching rows are not found.
3 = drop when column names match. Drop when matching rows are not found.
See the wks.join() method.


(2018 SR0)

When the X column of a column/bar graph contains text, this text is used to label major ticks, ordered by row index. Prior to Origin 2018, when applying a worksheet data filter, plots registered the vacant ticks and labels of filtered data, though the data points were not plotted. This was changed in Origin 2018 so that ticks associated with filtered data no longer display. This only applies to X columns that contain text and are NOT Set as Categorical. 0 (default) = hide filtered data labels, 1 = restore old behavior and show data labels even though data are filtered.
wks.loadedgrid Read/write
0 if grid not loaded; 1 if grid loaded.

(9.1 SR0)

Long name of worksheet.
wks.maxRows Read only
Scan all columns and find the largest row index that has value. You can setup a worksheet with wks.nRows, but before filling it with values, wks.maxRows will still be zero. To reduce the size of a worksheet, use wks.nRows, as this property is only to get the longest column row size.
wks.multiX Read only
Multiple X columns: 1 = Yes, 0 = No.
wks.name$ Read/write
Worksheet name.


Number of matrix objects in a matrix sheet.
wks.nCols Read/write
Number of columns in the worksheet. Before Origin 8, this property was Read-Only
wks.nRows Read/write
Number of rows in the worksheet. Before Origin 8, this property was Read-Only. See also: wks.maxRows.
wks.rhw Read/write
Row heading width in units of 1/10 of cell height.


// Set to about 5 char height
range aa=2!; // 2nd sheet of active book
wks.sel Read only
Selection flags. The hex return number indicates what is selected in the worksheet. Values may be the following, or a combination of these bits: 0 = none, 1 = editing cell, 2 = column, 4 = row, 8 = range, and 16 = 1 column.
wks.useFont Read/write
Font usage: 1 = use selected font, 0 = use system font.

(8.0 SR0)

Show/hide specified User Parameter. For example:
wks.UserParam1=1; // Show the first user parameter

(8.0 SR0)

Access the User Parameter's name. For example:
// Set parameter name as "Site Index"
wks.UserParam1$="Site Index";

(9.0 SR0)

Read only
Number of visible columns (not include the hidden columns) in the worksheet.

(9.0 SR0)

Read only
Number of visible rows (not include the hidden rows) in the worksheet.

There is no LabTalk property or command for merging selected worksheet cells but you can accomplish this by capturing the menu id of the Merge cells toolbar button and using it with the menu -e command.


Method Description
wks.addCol(name) Add a single named column to the end of the worksheet. If name is not specified, a generic name is chosen.
wks.colSel(colNum, n) Column selection. If n = 1, select the colNum column. If n = 0, deselect the colNum column.
wks.copy(strRegister, Col, Row) Copy(Z): Copy entire wks into string register %Z. (It is recommended that you use %Z which can hold up to 6,290 characters. If the text is too large, it is not copied and no error occurs.) See also: wks.paste().
Copy(Z, n): copy all rows of column n.
Copy(Z, 0, n): copy all columns of row n.
See the colcopy, colcopy, wcopy and wrcopy X-Functions for more options.
wks.deleteRows(rowBegin[,numRows, colBegin, colEnd])

(2016 SR0)

Delete a range of rows. Specifying only rowBegin deletes rowBegin in all columns in the worksheet.
Adding option numRows deletes numRows from rowBegin, in all columns.
Use colBegin and colEnd to limit deletion of rows to specified columns, from (a) colBegin to the last column in the sheet (colEnd not specified), or (b) from colBegin to colEnd.
See examples.
Also, see wks.insertRows, below.
wks.findLabels(ind, K[,n]) Finds an apparent label in a column of data (Origin worksheet or Excel workbook. If an Excel worksheet is active, make sure that the internal data has been updated (as with layer -s) before use).
ind = (required) index of the column in which to find label;
K = (required) global string variable letter to store the found label string;
n = (optional) 0 to disregard selection, 1 to consider selection inside the column if only a range of rows inside the column is selected (if nothing in the column is selected or if the whole column is selected, treat as 0) By default (i.e. if n is omitted), it is considered to be 0.

(9.0 SR0)

Test whether there are filters applied in the worksheet. If yes, return 1, else return 0. For more details about filter property scripts, please see wks.col.filter.
wks.insert(name list) Insert the list of columns at the current location. The current column position is specified by wks.col. The list consists of one or more desired column names separated by spaces. If a column name is already used, it is automatically enumerated.
wks.insertRows(rowBegin[,numRows, colBegin, colEnd])

(2016 SR0)

Insert a range of rows. Specifying only rowBegin inserts one row before rowBegin in all columns in the worksheet.
Adding option numRows inserts numRows from rowBegin, in all columns.
Use colBegin and colEnd to limit insertion of rows to specified columns, from (a) colBegin to the last column in the sheet (colEnd not specified), or (b) from colBegin to colEnd.
See examples.
Also, see wks.deleteRows, above.

(9.0 SR0)

Test whether the column (specified by column number, colNum), is hidden. If hidden, return 1, and 0 for else.
wks.isColSel([colNum]) If colNum is included as an argument, the method returns the selection state of colNum. 0 = the column isn't selected. 1 = entire column is selected. 2 = a range of the column is selected.
If colNum is not included as an argument, this method returns the number of columns selected (partial and entire selections).

(9.0 SR0)

Test whether the row (specified by row number, rowNum), is hidden. If hidden, return 1, and 0 for else.
[ToWks!]wks.join(FromWks) Join the worksheet specified by FromWks to the worksheet specified by ToWks. This method adds the columns of FromWks to ToWks according to the method specified by wks.joinmode.

If ToWks is not specified, then the currently active worksheet is used.


(8.0 SR1)

Control the display of worksheet column labels. No argument = do not show any labels, otherwise a string containing column label row characters, for example:
// Show Long Name and Comments, if they are not empty
// Do not show any label rows
// Set to show long name, units and comments
// Show Comments, User Parameter 1, and Long Name

The prefixes +, - and * were added in Origin 8 SR2.
The prefixes < and > were added in Origin 2017.

// To remove Units
// To insert Sample Rate and Sparklines at the top
// To append Units to the bottom
// To move F(x)= to the bottom
//To move Comments to the top

Note that you can also use + and * to "move" (add) a label row to top or bottom. The characters < and > will do nothing if the label row is not already shown.

wks.paste(strRegister, Col, Row) Paste the contents of a string register (specified without the %) into the cell beginning at (Col, Row).

(9.0 SR0)

Run or re-apply filter. For more details on filter property scripts, please see wks.col.filter.
wks.setaslabel(type, rowNum, label, append)


Set or append one row as LongName, Unit, Comment, etc.

type : Label type , L, C, U, P, etc.

rowNum : The Number of the row to set as label (This row will not be removed); -1 = remove the active row when you set it as the label (Note: you need to select the row before running this script).

label : 1 = select the label row, 0 = select the data row.

append : 1 = append the content in the selected row to label (Only works for Long Name and Comments); 0 = use the content in the selected row to replace the original content.

//Set the second label row as the Long name.
//Append the fourth data row to the Comment.
//Set the first data row as the Unit.
//(The first data row should be active, 
// and it will be removed after running the script).
worksheet -s 0 1 0 1;  
wks.template( FileName[,[WinName],NumRows]) Apply the template named FileName to <NumRows> rows of window WinName
wks.GetNextVisibleRow(n) Find the next visible row starting from the given row n. The GetNextVisibleRow(n) will check the rows after row n one by one, it outputs the row index if a visible row was found. So wks.GetNextVisibleRow(0) will give you the first visible row.


Work with Worksheet Columns and Rows

When a new worksheet is created, there are 2 columns and 32 rows by default. To read or set the number of worksheet columns and rows, you can use the wks.ncols and wks.nrows properties.

newsheet; // Add a new worksheet
wks.ncols = 5; // Set the number of columns to 5
wks.nrows = 100; // Set the number of rows to 100

Note that Origin will delete columns beyond (i.e., to the right of) the number you specify. So, in general, it is safer to use the wks.addCol(name) method to add columns.

wks.addCol(Does); // Add a column with short name 'Does'

Regarding worksheet rows, two properties are similar, wks.maxRows and wks.nRows. The former finds the largest row index in the worksheet that has a value, while the latter sets or reads the number of rows in the worksheet. The following script illustrates how to use these two properties:

newbook; // Create a new workbook
col(b) = {1:10}; // Fill 10 numbers to column B
wks.maxRows = ; // Returns 10
wks.nRows = ; // Returns 32

Display Worksheet Column Labels

This script creates an empty table for the average temperature in different cities. In this example, we will create a user-defined parameter and show the worksheet long name, unit and the user-defined parameter.

range ww = !;  // Define a range, on active worksheet
ww.name$ = "Average Temperature";  // Rename the worksheet
ww.ncols = 13;  // Set total number of columns
ww.userParam1$ = Month;  // Define a new user parameter label
// Show the worksheet long name, unit and a user parameter
Col(1)[L]$ = City;  // Set column long name
stringarray month = {"Jun.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", 
                   "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."};
loop(ii, 2, 13)
        Col($(ii))[L]$ = Temperature;  // Set column long name
        Col($(ii))[U]$ = \+(o)F;  // Set column unit
        // Set column user parameter
        Col($(ii))[D1]$ = month.getAt(ii-1)$;  

Get the unhidden value from the column in worksheet

1. Assume some of values are hidden by Filter in worksheet, the script below will list the unhidden value in the column.

//with the worksheet active
for (int ii=1; ii <= wks.nrows; ii++){
if(wks.isRowHidden(ii)){       //continue id there is a hidden row
  ii = wks.GetNextVisibleRow(ii);   //get the 1st not hidden row number after this hidden row

2. The second example shows how the function GetNextVisibleRow works, assume we have a worksheet as shown below:


Run the script with the worksheet active:

//with the worksheet active
type "The 1st visable row is $(wks.GetNextVisibleRow(0))";
type "The 1st visible row after row $(ii) is $(a$(ii))";

The results output:

The 1st visible row is 1
The 1st visible row after row 1 is 3
The 1st visible row after row 2 is 3
The 1st visible row after row 3 is 5

See Also

Worksheet Manipulation X-Functions