Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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

Release History

Release History

This version
History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
rst_simplespreadsheet-0.1.1.tar.gz (4.0 kB) Copy SHA256 Checksum SHA256 Source Nov 25, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting