Skip to main content

Simple spreadsheet extension for reStructuredText tables.

Project description

Register a simplespreadsheet directive to do calculations in a table.

Install

pip install rst_simplespreadsheet  # or
easy_install rst_simplespreadsheet

Usage

Use it as an extension to rst2pdf:

rst2pdf -e rst_simplespreadsheet ...

Syntax

Formulae are pieces of text enclosed in ={…}. Only one formula per cell is supported.

The simplest formula is a number, like this:

={4}

This define the cell value to 4. A cell has value 0 (zero) unless it contains a formula.

You can reference the value of other cells using alphanumerical identifiers. Columns are identified using letters, from a to z then from aa to az, ba to bz and so on. Rows are identified using numbers. The first row is 1 and header rows are not numbered (thus not referenceable).

For example, the formula to calculate the product of cells a1 and a2 is:

={a1 * a2}

There are two special characters, # and @, used to reference the current row and the current column, respectively.

For example, to calculate the product of cells b and f on the current row:

={b# * f#}

and to calculate the sum of rows 1 and 2 in the current column:

={@1 + @2}

Functions

The spreadsheet can calculate cell values using Python functions. These functions have to be defined and registered in the SpreadSheet class first.

For now, only the function sum is defined:

={sum("a1:a20")}

Examples

You can do a simple table with totals like this one:

Qty Rate Price
2 1 $ 2 $
4 3 $ 12 $
1 5 $ 5 $
3 7 $ 21 $
Total 40 $

with this code:

.. simplespreadsheet::
    +------+--------+-------------------+
    | Qty  | Price  |  Total            |
    +======+========+===================+
    | ={2} | ={1} $ | ={a# * b#} $      |
    +------+--------+-------------------+
    | ={4} | ={3} $ | ={a# * b#} $      |
    +------+--------+-------------------+
    | ={1} | ={5} $ | ={a# * b#} $      |
    +------+--------+-------------------+
    | ={3} | ={7} $ | ={a# * b#} $      |
    +------+--------+-------------------+
    | *Total*       | ={sum("c1:c4")} $ |
    +------+--------+-------------------+

Adding more functions

For now, the only available function is sum(). You can easily add new functions by adding them to SpreadSheet.tools. Please share your improvements by forking the project on github: https://github.com/patrickfournier/simplespreadsheet

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
rst_simplespreadsheet-0.1.1.tar.gz (4.0 kB) Copy SHA256 hash SHA256 Source None Nov 25, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page