OriginPro
 
Loading...
Searching...
No Matches
originpro.worksheet.WSheet Class Reference
Inheritance diagram for originpro.worksheet.WSheet:
originpro.base.DSheet originpro.base.BaseLayer originpro.base.BaseObject

Public Member Functions

def rows (self)
 
def cols (self)
 
def cols (self, val)
 
def get_book (self)
 
def lt_col_index (self, col, convert_negative=False)
 
def from_df (self, df, c1=0, addindex=False, head='')
 
def to_df (self, c1=0, numcols=-1, cindex=-1, head='')
 
def to_list (self, col)
 
def from_list (self, col, data, lname='', units='', comments='', axis='', start=0)
 
def get_label (self, col, type='L')
 
def set_label (self, col, val, type='L')
 
def get_labels (self, type_='L')
 
def set_labels (self, labels, type_='L', offset=0)
 
def from_dict (self, data, col=0, row=0)
 
def header_rows (self, spec='')
 
def cols_axis (self, spec='', c1=0, c2=-1, repeat=True)
 
def del_col (self, c1, nc=1)
 
def clear (self, c1=0, ncols=0, c2=-1)
 
def sort (self, col, dec=False)
 
def to_list2 (self, r1=0, r2=-1, c1=0, c2=-1)
 
def from_list2 (self, data, row=0, col=0)
 
def as_date (self, col, fmt)
 
def as_time (self, col, fmt)
 
def move_cols (self, n, c1, ncols=1)
 
def plot_cloneable (self, template)
 
def set_formula (self, col, formula)
 
def report_table (self, *args)
 
def to_xy_range (self, colx, coly, colyerr, colxerr='')
 
def to_col_range (self, col)
 
def merge_label (self, type_='L', unmerge=False)
 
def cell (self, row, col)
 
def set_cell_note (self, row, col, text)
 
- Public Member Functions inherited from originpro.base.DSheet
def __str__ (self)
 
def __repr__ (self)
 
def shape (self)
 
def shape (self, val)
 
def remove_DC (self)
 
def has_DC (self)
 
def from_file (self, fname, keep_DC=True, dctype='', sel='', sparks=False)
 
def lt_range (self, use_name=True)
 
def get_book (self)
 
def get_labels (self, type_='L')
 
def set_labels (self, labels, type_='L', offset=0)
 
def tabcolor (self)
 
def tabcolor (self, rgb)
 
- Public Member Functions inherited from originpro.base.BaseLayer
def __str__ (self)
 
def activate (self)
 
def destroy (self)
 
- Public Member Functions inherited from originpro.base.BaseObject
def __init__ (self, obj)
 
def __del__ (self)
 
def __str__ (self)
 
def __bool__ (self)
 
def index (self)
 
def get_str (self, prop)
 
def get_int (self, prop)
 
def get_float (self, prop)
 
def set_str (self, prop, value)
 
def set_int (self, prop, value)
 
def set_float (self, prop, value)
 
def method_int (self, name, arg='')
 
def method_float (self, name, arg='')
 
def method_str (self, name, arg='')
 
def lt_exec (self, labtalk)
 
def name (self)
 
def name (self, value)
 
def lname (self)
 
def lname (self, value)
 
def comments (self)
 
def comments (self, value)
 
def show (self)
 
def show (self, value)
 
def usertree (self)
 
def usertree (self, tr)
 
def userprops (self)
 

Additional Inherited Members

- Public Attributes inherited from originpro.base.BaseObject
 obj
 

Detailed Description

This class represents an Origin Worksheet, it holds an instance of a PyOrigin Worksheet.

Member Function Documentation

◆ as_date()

def originpro.worksheet.WSheet.as_date (   self,
  col,
  fmt 
)
set col as date format

Parameters:
    col (int or str): If int, column index. If str, column name, short name first, then long name.
    fmt (int or str): can be custom format string, or date display option as int

Returns:
    (None)

Examples:
    wks=op.find_sheet()
    data = [1,2,3,4,5,6]
    wks.from_list(0, data)
    wks.as_date(0, "yyyy'Q'q")
See Also:

◆ as_time()

def originpro.worksheet.WSheet.as_time (   self,
  col,
  fmt 
)
set col as time format

Parameters:
    col (int or str): If int, column index. If str, column name, short name first, then long name.
    fmt (int or str): can be custom format string, or time display option as int

Returns:
    (None)

Examples:
    wks=op.find_sheet()
    data = [1.1,2.2,3.3,4.4,5.5,6.6]
    wks.from_list(0, data)
    wks.as_time(0, "D:hh':'mm':'ss TT")
See Also:

◆ cell()

def originpro.worksheet.WSheet.cell (   self,
  row,
  col 
)
It returns the contents of a worksheet cell as a string.

Parameters:
    row (int): the row index.
    col (int, str): if int, it is the column index, otherwise the column name

Returns:
    (str) the contents of a worksheet cell as a string.
Examples:
    wks=op.find_sheet()
    ls = [1,2,3]
    wks.from_list(0,ls)
    nVal = wks.cell(0,0)
    print(nVal)

◆ clear()

def originpro.worksheet.WSheet.clear (   self,
  c1 = 0,
  ncols = 0,
  c2 = -1 
)
Clear data in worksheet

Parameters:
    c1 (int or str): starting col, if int, column index. If str, column name, short name first, then long name.
    ncols(int): number of columns to clear if > 0, cannot specify togeher with c2
    c2 (int or str): ending col, if int, column index. If str, column name, short name first, then long name.

Returns:
    (int): 0 for success, otherwise an internal error code

Examples:
    wks.clear()#clear all
    wks.clear(1)#clear from 2nd column to the end
    wks.clear(1,2)#clear from 2nd and 3rd

◆ cols() [1/2]

def originpro.worksheet.WSheet.cols (   self)
get the last column index in worksheet, this is the same as shape[1]
Parameters:

Returns:
    get the last column index in worksheet
Examples:
    wks=op.find_sheet()
    ncols = wks.cols

◆ cols() [2/2]

def originpro.worksheet.WSheet.cols (   self,
  val 
)
set the number of columns in worksheet
Parameters:
    val(int):number of columns
Returns:
    the last column index in worksheet
Examples:
    wks=op.find_sheet()
    wks.cols=5

◆ cols_axis()

def originpro.worksheet.WSheet.cols_axis (   self,
  spec = '',
  c1 = 0,
  c2 = -1,
  repeat = True 
)
Set column plotting designations with a string pattern.

Parameters:
    spec (str): A combination of 'x', 'y', 'z', etc letters
    c1 (int or str): Starting column to set
    c2 (int or str): Last column to set. c2 < 0 sets to last column
    repeat (bool): Repeat the last designation letter or not

Returns:
    None

Examples:
    wks.cols_axis('nxy') # 1st col none, 2nd=x, others=y.
    wks.cols_axis() # Clear designations from all columns.

◆ del_col()

def originpro.worksheet.WSheet.del_col (   self,
  c1,
  nc = 1 
)
Delete worksheet columns

Parameters:
    c1 (int or str): Starting column to delete, <0 supported as from the end
    nc (int):      Number of columns to delete starting from c1
Examples:
    wks.del_col(0)# del col A
    wks.del_col('C', 2)#del col C and D

◆ from_df()

def originpro.worksheet.WSheet.from_df (   self,
  df,
  c1 = 0,
  addindex = False,
  head = '' 
)
Sets a pandas DataFrame to an Origin worksheet.

Parameters:
    df (DataFrame): Input DataFrame object
    c1 (int or str): Starting column index
    addindex (bool): add an index column at c1 if df has text indices
    head(str): if not specified, column longname is used if df has column names,
        head can be one of the Column Label Row character like 'L', 'C', or a user parameter by its name

Returns:
    None

Examples:
    wks=op.find_sheet()
    my_df = pd.DataFrame({'aa':[1,2,3], 'bb':[4,5,6]})
    wks.from_df(my_df)

    import pandas as pd
    fname = op.path('e') + "Samples\\Import and Export\donations.csv"
    df = pd.read_csv(fname)
    wks.from_df(df,'B')

◆ from_dict()

def originpro.worksheet.WSheet.from_dict (   self,
  data,
  col = 0,
  row = 0 
)
Set a dictionary into a Worksheet. Keys are not used for any purpose.

Parameters:
    data (dict): The data to set
    col (int or str): If int, column index. If str, tries short name and if not exists, tries column long name
    row (int): Row index to start setting the data

Returns:
    None

Examples:
    data ={'aa': [1,2,3], 'bb':[4,5,6]}
    wks.from_dict(data)
    wks.from_dict(data,'C')

◆ from_list()

def originpro.worksheet.WSheet.from_list (   self,
  col,
  data,
  lname = '',
  units = '',
  comments = '',
  axis = '',
  start = 0 
)
Sets a list object into an Origin column, optionally specifying long name, units ,comments label row values.

Parameters:
    col (int or str): If int, column index. If str, tries short name and if not exists, tries column long name
    data (list): data to put into column
    lname (str): Optional column long name
    units (str): Optional column units
    comments (str): Optional column comments
    axis (str): empty will not set, otherwise set column designation for plotting,
                can be X,Y,Z, or N(None), E(Yerr), M(Xerr), L(label)
                see https://www.originlab.com/doc/Origin-Help/WksCol-SetDesignation
    start(int): row offset
Returns:
    None

Examples:
    data = [1,2,3,4,5]
    wks.from_list(1, data)
    wks.from_list('Intensity', data, units='a. u.', axis='Y')
    wks.from_list(0, data, start=2)

◆ from_list2()

def originpro.worksheet.WSheet.from_list2 (   self,
  data,
  row = 0,
  col = 0 
)
set a block of cells

Parameters:
    data (list): a list of lists of values
    row (int): starting row index
    col (int or str): starting col, by index of by name

Returns:
    (None)

Examples:
    wks=op.find_sheet()
    #append a row to worksheet
    data = [ [10], [40] ]
    wks.from_list2(data, wks.rows)
See Also:
    to_list2

◆ get_book()

def originpro.worksheet.WSheet.get_book (   self)
Returns parent book of sheet.

Parameters:

Returns:
    (WBook)

Examples:
    wks2 = wks.get_book().add_sheet('Result')

Reimplemented from originpro.base.DSheet.

◆ get_label()

def originpro.worksheet.WSheet.get_label (   self,
  col,
  type = 'L' 
)
Return a column label row text.

Parameters:
    col (int or str): If int, column index. If str, tries short name and if not exists, tries column long name
    type (str): A column label row character (see https://www.originlab.com/doc/LabTalk/ref/Column-Label-Row-Characters) or a user defined parameter name

Returns:
    (str)

Examples:
    wks=op.find_sheet()
    comments = wks.get_label(1,'C')

◆ get_labels()

def originpro.worksheet.WSheet.get_labels (   self,
  type_ = 'L' 
)
Return columns label row text.

Parameters:
    type_ (str): A column label row character (see https://www.originlab.com/doc/LabTalk/ref/Column-Label-Row-Characters) or a user defined parameter name

Returns:
    (list)

Examples:
    wks=op.find_sheet()
    comments = wks.get_labels('C')

Reimplemented from originpro.base.DSheet.

◆ header_rows()

def originpro.worksheet.WSheet.header_rows (   self,
  spec = '' 
)
Controls which worksheet label rows to show, same as LabTalk wks.labels string.

Parameters:
    spec (str): A combination of letters. See https://www.originlab.com/doc/LabTalk/ref/Column-Label-Row-Characters

Returns:
    None

Examples:
    wks.header_rows('lu')# Show only long-name and unit.
    wks.header_rows()# Remove all label rows, keep only heading.

◆ lt_col_index()

def originpro.worksheet.WSheet.lt_col_index (   self,
  col,
  convert_negative = False 
)
convert a 0-offset index to LabTalk index which is 1-offset

Parameters:
    col (int or str): If int, column index. If str, tries short name and if not exists, tries column long name, <0 supported as from the end

Return:
    (int) 1-offset column index

Examples:
    ii = wks.lt_col_index('Intensity')
    if ii < 1:
        print('no such column')

◆ merge_label()

def originpro.worksheet.WSheet.merge_label (   self,
  type_ = 'L',
  unmerge = False 
)
merge or unmerge specified label row
Parameters:
    type_(string):can be 'L' for longname, 'U' for Units, 'C' for comments
    unmerge(bool):false for merge, true for unmerge
Returns:
    (None)
Examples:
    wks=op.find_sheet()
    arrLName = ['longname','longname']
    wks.set_labels(arrLName)
    wks.merge_label()

◆ move_cols()

def originpro.worksheet.WSheet.move_cols (   self,
  n,
  c1,
  ncols = 1 
)
moves a contiguous set of columns

Parameters:
    n (int): by how many positions to move; if negative, columns are moved left,
             otherwise right.
    c1 (int): the index of the first columns in the contiguous set.
    ncols (int): the total number of columns in the contiguous set.

Returns:
    (bool)    returns True for success.

Examples:
    wks=op.find_sheet()
    wks.move_cols(2, 1, 3)    # it moves three columns, beginning with the second column,
                            # by two positions right.
See Also:

◆ plot_cloneable()

def originpro.worksheet.WSheet.plot_cloneable (   self,
  template 
)
Plots workbook data into a cloneable graph template

Parameters:
    template (str): Cloneable graph template name.
Returns:
    (None)
Example:
    ws = op.new_book('w', hidden = False)[0]
    ws.from_file(op.path('e') + r'Samples\Statistics\Automobile.dat', True)
    ws.plot_cloneable('mytemplate')

◆ report_table()

def originpro.worksheet.WSheet.report_table (   self,
args 
)
Get Report table as DataFrame
Parameters:
    args: Table names as string
Example:
    wks = op.find_sheet()
    df1 = wks.report_table("Parameters")

◆ rows()

def originpro.worksheet.WSheet.rows (   self)
Get the last row index in worksheet with data, hidden rows has no effect on this
This is different from shape[0] which does not care of having data or not
Parameters:

Returns:
    the last row index in worksheet with data
Examples:
    wks=op.find_sheet()
    nrows = wks.rows

◆ set_cell_note()

def originpro.worksheet.WSheet.set_cell_note (   self,
  row,
  col,
  text 
)
create or update a cell's Note

Parameters:
    row (int):          the row index.
    col (int, str):     if int, it is the column index, otherwise the column name
    text (str):         The cell note content
Returns:
    (None)
Examples:
    wks=op.find_sheet()
    wks.set_cell_note(0,0,'test cell note')

◆ set_formula()

def originpro.worksheet.WSheet.set_formula (   self,
  col,
  formula 
)
set column formula
Parameters:
    col (int or str): If int, column index. If str, column name, short name first, then long name.
    formula(str): column formula (Fx) to set.
Example:
    wks = op.find_sheet()
    wks.set_formula('B', 'A+1')

◆ set_label()

def originpro.worksheet.WSheet.set_label (   self,
  col,
  val,
  type = 'L' 
)
Set a column label row text.

Parameters:
    col (int or str): If int, column index. If str, tries short name and if not exists, tries column long name
    val (str): the text to set
    type (str): A column label row character (see https://www.originlab.com/doc/LabTalk/ref/Column-Label-Row-Characters) or a user defined parameter name

Examples:
    wks=op.find_sheet()
    wks.set_label('A','long name for col A')
    wks.set_label(1, 'for col B, add user parameter if not there', 'Channel')

◆ set_labels()

def originpro.worksheet.WSheet.set_labels (   self,
  labels,
  type_ = 'L',
  offset = 0 
)
Set columns label row text.

Parameters:
    labels (list): the text to set
    type_ (str): A column label row character (see https://www.originlab.com/doc/LabTalk/ref/Column-Label-Row-Characters) or a user defined parameter name

Examples:
    wks=op.find_sheet()
    wks.set_labels(['long name for col A', 'long name for col B'], 'L')

Reimplemented from originpro.base.DSheet.

◆ sort()

def originpro.worksheet.WSheet.sort (   self,
  col,
  dec = False 
)
Sort worksheet data by a specified column

Parameters:
    col (int or str): If int, column index (1-offset). If str, column name, short name first, then long name.
    dec (bool): Ascending(False) or Descending(True)

Returns:
    (int): 0 for success, otherwise an internal error code

Examples:
    wks.sort('A')#sort using 1st col, ascending
    wks.sort(0, True)#sort using 1st col, descending

◆ to_col_range()

def originpro.worksheet.WSheet.to_col_range (   self,
  col 
)
Make Column range string
Parameters:
    col(int or str): If int, column index. If str, tries short name and if not exists, tries column long name
Returns:
    XY range string
Examples:
    wks=op.find_sheet()
    wks.cols=3
    strRange = wks.to_col_range(1)

◆ to_df()

def originpro.worksheet.WSheet.to_df (   self,
  c1 = 0,
  numcols = -1,
  cindex = -1,
  head = '' 
)
Creates a pandas DataFrame from an Origin worksheet.

Parameters:
    c1 (int or str): column to start the export
    numcols (int): Total number of columns, -1 to the end
    cindex (int or str): Column to use for DataFrame index if specified
    head (str): user parameter or built-in label row name, if not specified, lname(column long name), or short name if lname empty or duplicated
Returns:
    (DataFrame)

Examples:
    df = wks.to_df(2)#from 3rd column

    #use col(A) as index, and B and C as data
    df1 = wks.to_df('B', 2, 'A')

    #to use a user defined label row as column heading
    df2 = wks.to_df(head='Tag')

◆ to_list()

def originpro.worksheet.WSheet.to_list (   self,
  col 
)
Creates a list object from the data in an Origin column.

Parameters:
    col (int or str): If int, column index. If str, tries short name and if not exists, tries column long name

Returns:
    (list)

Examples:
    data1 = wks.to_list(1)
    data2 = wks.to_list('Intensity')

◆ to_list2()

def originpro.worksheet.WSheet.to_list2 (   self,
  r1 = 0,
  r2 = -1,
  c1 = 0,
  c2 = -1 
)
get a block of cells as a list of lists

Parameters:
    r1 (int): beginning row index
    r2 (int): ending row index (inclusive), -1 to the end
    c1 (int): beginning column index
    c2 (int): ending column index (inclusive), -1 to the end

Returns:
    (list) list of lists of results

Examples:
    #copy 1st row and append to last row
    ll = wks.to_list2(0,0)
    wks.from_list2(ll,wks.rows)

◆ to_xy_range()

def originpro.worksheet.WSheet.to_xy_range (   self,
  colx,
  coly,
  colyerr,
  colxerr = '' 
)
Make XY range string from columns
Parameters:
    colx, coly, colyerr, colxerr:type can be int or str, If int, column index. If str, tries short name and if not exists, tries column long name

Returns:
    XY range string
Examples:
    wks=op.find_sheet()
    wks.cols=3
    strRange = wks.to_xy_range(0,1,2)

The documentation for this class was generated from the following file: