Resolver One Library Documentation

API for Col

Back to documentation index page.

Classes

Class Col

class Col(RowCol):
    def __init__(self, worksheet, index):

Col objects represent columns in a spreadsheet. They provide convenient ways of accessing cells contained in the column, and setting traits for the whole column.

It is not intended that you create Col instances directly, but access them by indexing the 'Cols' attribute on worksheets. You can obtain a 'Col' object by indexing 'Cols' with the string identifier (for example 'D') or the integer index of the column (for example 4). If there is a 'HeaderRow' set on the worksheet, then you can index 'Cols' using the titles in the header row.

If the index is invalid then an IndexError will be raised.

Col objects themselves have a Cells property that is indexable. This takes a single row index and returns the cell at that location. The following code fetches column 3 ('C'), and then obtains background color of the cell at location (3, 6) by indexing the column.

sheet_1 = workbook['Sheet1']

column_c = sheet_1.Cols['C']

color = column_c.Cells[6].BackColor

There is also a shortcut available if you want to get the value of a cell:

value = column_c[6]  # equivalent to column_c.Cells[6].Value

The row index can be any valid row index accepted by the worksheet. Usually this will be an integer greater than zero, but if you have a 'HeaderCol' set on the worksheet then you can use the column titles as a row index.

An invalid index on a column will raise an IndexError.

You can also iterate over the cells in the Col, using the Cells property. It returns every cell in the column between MinRow and MaxRow on the worksheet. MinRow is the lowest row on the worksheet that contains a populated cell, MaxRow is the highest row on the worksheet to contain a populated cell.

for cell in column_c.Cells:
    print cell.BackColor

Once again, there is a shortcut to allow you to easily iterate over the values of the cells in the Col:

for value in column_c:
    print value

Properties

BackColor

BackColor = property(get, set)

The background colour to display in the grid. This must be a Color from System.Drawing.

Bold

Bold = property(get, set)

This specifies whether the cell's content is bold. The default is False.

BorderBottom

BorderBottom = property(get, set)

This specifies whether the cell has a border along its bottom edge. It must be either True or False.

BorderLeft

BorderLeft = property(get, set)

This specifies whether the cell has a border along its left edge. It must be either True or False.

BorderRight

BorderRight = property(get, set)

This specifies whether the cell has a border along its right edge. It must be either True or False.

BorderTop

BorderTop = property(get, set)

This specifies whether the cell has a border along its top edge. It must be either True or False.

ColHidden

ColHidden = property(get, set)

This specifies whether the column is hidden. Has no effect when set on a row or a cell. Setting it on a worksheet is not advised.

ColWidth

ColWidth = property(get, set)

This specifies the width of a column, in pixels. It must be a non- negative integer. Has no effect when set on a row or a cell.

Color

Color = property(get, set)
The colour to display text in the cells of the grid. This must be a
Color from System.Drawing.

Currency

Currency = property(get, set)

This specifies the currency formatting of a cell (if any). It must be a value from the Currency from Library.Currency.

DecimalPlaces

DecimalPlaces = property(get, set)

This specifies how many decimal places should be displayed for numbers. Any integer from 0 to 15 can be used.

FontFamily

FontFamily = property(get, set)

The FontFamily used to display values. This is a string representing the font to use, for example "Tahoma".

FontSize

FontSize = property(get, set)

A number representing the size of the font used to display a cell's value. An integer (from 1 to 409).

Formatter

Formatter = property(get, set)

A callable (e.g., function) to provide a custom text representation for values in the grid. It is used every time a value for a cell needs to be displayed in the grid.

When your custom formatter is called, it will be passed two arguments. These are, the value in the cell (which can be an object of any type) and the cellFormatter. The cellFormatter is the formatter that would have been used if you hadn't provided a custom formatter. Your custom formatter can use the cellFormatter to generate a String from the value, and then modify it. Alternatively your function can ignore the cellFormatter if you don't need it. The cellFormatter takes into account other traits that affect the String representation, like Currency, StripZeros and DecimalPlaces. The cellFormatter takes one argument and returns a String.

To display numbers in the column C as kilometers:

def customFormatter(v, cellFormatter):
    return cellFormatter(v) + ' km'
workbook['Sheet1'].Cols['C'].Formatter = customFormatter

or the same in just one line of code, using lambda:

workbook['Sheet1'].Cols['C'].Formatter = lambda v, cf: cf(v) + ' km'

Your custom formatter should return a String.

Index

Index = property(get, set)

This is a get only property, which is an integer (greater than zero) representing the index of the row or column.

Italic

Italic = property(get, set)

This specifies whether the cell's content is italic. The default is False.

Location

Location = property(get)

A get only property returning the location of a Col. The location of a Col is a tuple containing (worksheet, Index, 0).

NegativeTextColor

NegativeTextColor = property(get, set)

This is the colour used to display negative numbers. This must be a Color from System.Drawing.

RowHeight

RowHeight = property(get, set)

This specifies the height of a row, in pixels. It must be a non- negative integer. Has no effect when set on a column or a cell.

RowHidden

RowHidden = property(get, set)

This specifies whether the row is hidden. Has no effect when set on a column or a cell. Setting it on a worksheet is not advised.

ShowNegativeSymbol

ShowNegativeSymbol = property(get, set)

This specifies whether or not to display the negative symbol for negative numbers. It is set to True or False.

ShowSeparators

ShowSeparators = property(get, set)

This specifies whether or not to show the thousand separator commas in numbers. It is set to True or False.

Strikethrough

Strikethrough = property(get, set)

This specifies whether the cell's content is struck through. The default is False.

StripZeros

StripZeros = property(get, set)

This specifies whether or not to strip trailing zeros (after the decimal point) for numbers. It is set to True or False.

Underline

Underline = property(get, set)

This specifies whether the cell's content is underlined. The default is False.

WebEditable

WebEditable = property(get, set)

This specifies whether or not a cell will be editable when viewed from the Resolver Server.

Wrap

Wrap = property(get, set)

This specifies whether or not long text should wrap within a cell. It is set to True or False.

Methods

UseNaturalDecimalPlaces

def UseNaturalDecimalPlaces(self):

Called without arguments, and does not return anything.

This is used on spreadsheet elements to restore the element to using the default values for number of DecimalPlaces and whether to StripZeros. The default values for these traits are 15 and True respectively.