Simple spreadsheet extension for reStructuredText tables.
Project description
Register a simplespreadsheet directive to do calculations in a table.
Install
=======
Usage
=====
Use it as an extension to rst2pdf:
rst2pdf -e <path to simplespreadsheet.py> ...
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
Install
=======
Usage
=====
Use it as an extension to rst2pdf:
rst2pdf -e <path to simplespreadsheet.py> ...
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for rst_simplespreadsheet-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76ba149005a869319ad775de9bf6c73a8b8a6a2ecf6a3d740012bf7bbeca78a4 |
|
MD5 | e967127dcf65d553b30644aa6aa73874 |
|
BLAKE2b-256 | 1a52eaacedeb865154f20a7bbef428a96c71f71124c07ac65d67b614aacf62ce |