Documentation for module table

Download the sourcecode.

This module exports two classes: RowTable and ColTable. A RowTable is a table that is filled row by row, a ColTable is filled col by col. After all values have been entered into the table, you can get an external representation of the table in three formats: LaTeX, HTML and CSV. HTML and CSV are not fully supported, some operations make only sense for LaTeX.

Example:

    tab = RowTable()
    tab.addColSeparator(0)
    tab.addRow(1,2,3)
    tab.addRowSeparator()
    tab.addRow(4,5,6)
    latexOutput = tab.getAsLatex()

The code above would produce a table like that:

  1 | 2  3
  --+-------
  4 | 5  6

For use with LaTeX you should put something like this into your document:

\usepackage{dcolumn}
% the 1st arg is the decimal separator used in the .tex file,
% the 2nd arg is the decimal separator that should be used in the .dvi
%   file
% the 3rd specifies the number of digits to the left and to the
%   right of the decimal separator
% Remember: the .tex file may also contain grouping separators
\newcolumntype{d}[0]{D{.}{.}{3}}


Summary

Functions

No functions exported.

Classes


Detail

Functions

No functions exported.

Classes

class AbstractTable:
def getAsCsv(self, colsep = ';'):

Returns a string with the table in CSV (comma separated values) format. Some information might be lost when exporting the table to the CSV format.

def getAsHtml(self):

Returns a string with the table in HTML format. Some information might be lost when exporting the table to HTML format.

def getAsLatex(self):

Returns a string with the table in LaTeX format.

def isLongtable(self, bool):

Specifies if the latex package longtable should be used for this table.

[back to summary]
class ColTable:
def __init__(self, caption = None):

Creates a new ColTable with an optional caption. A ColTable is a table that is constructed by adding cols to the table, i.e. the table is built col by col.

def addCol(self, col, header = ''):

Adds a new col to the table. header is the header of the col. The first col of the table determines the length of all other cols. If the new col is not the first col and its length is the same as the the first col's length, a TableError is raised.

Exceptions:TableError, msg
def addColSeparator(self, afterCol = -1):

Adds a separator after col afterCol. The first col has index 0. If afterCol is negative, a separator is inserted after the most recently added col.

def addRowSeparator(self, afterRow):

Adds a separator after row afterRow. The first row has index 0.

def setColFormat(self, type, colNo = -1):

Sets the (latex) format for column at index colNo (first col has index 0). If colNo is negative, the format for the most recently added col is set. The format only applies to cells with numerical content. Use setColTextFormat for setting the format of cells with textual content.

def setColTextFormat(self, type, colNo = -1):

Sets the (latex) format for column at index colNo (first col has index 0). If colNo is negative, the format for the most recently added col is set. The format only applies to cells with textual content. Use setColTextFormat for setting the format of cells with numerical content.

[back to summary]
class RowTable:
def __init__(self, caption = None):

Creates a new RowTable with an optional caption. A RowTable is a table that is constructed by adding rows to the table, i.e. the table is built row by row.

def addColSeparator(self, afterCol):

Adds a separator after col afterCol. The first col has index 0.

def addRow(self, row):

row is a list that contains the values for one row. If there are too many values in the list (i.e. a row with less cells than this has been added before) a exception is raised. If there are not enough values the rest is filled with the empty string.

A value can occupy several cells of a row. You can specify the number of cells a value occupies by inserting the tuple (colspan, value) into the row-list. colspan is the number of cells value occupies.

Example:

            addRow(['first', (2, 'hello world!'), 'fourth'])

inserts a row that is 4 cells wide into the table. The first cell contains the value first, the second and third cell together contain the value hello world! and the fourth cell contains the value fourth.

def addRowSeparator(self, afterRow = -1):

Adds a separator after row afterRow. The first row has index 0. If afterRow is negative, a separator is inserted after the most recently added row.

def setColFormat(self, type, colNo = -1):

Sets the (latex) format for column at index colNo (first col has index 0). The format only applies to cells with numerical content. Use setColTextFormat for setting the format of cells with textual content.

def setColTextFormat(self, type, colNo = -1):

Sets the (latex) format for column at index colNo (first col has index 0). The format only applies to cells with textual content. Use setColTextFormat for setting the format of cells with numerical content.

def setLastHeaderRow(self, index = -1):

Marks the 'index'-th row as the last header row. If index < 0, the most recently added row is marked as the last header row (in case no row has been added, an exception is raised).

[back to summary]

Author: Stefan Wehr
Website: http://www.stefanwehr.de
License: LGPL
Version: 2005-03-15
Date: 2005-03-15