Skip to main content

A plugin to pyexcel and provides the capbility to present and write data in text fromats

Project description

https://api.travis-ci.org/pyexcel/pyexcel-text.svg?branch=master https://codecov.io/github/pyexcel/pyexcel-xls/coverage.png

It is a plugin to pyexcel and extends its capbility to present and write data in text fromats mainly through tabulate:

  • “plain”

  • “simple”

  • “grid”

  • “pipe”

  • “orgtbl”

  • “rst”

  • “mediawiki”

  • “latex”

  • “latex_booktabs”

  • “json”

Usage

Here is the example usage:

>>> import pyexcel as pe
>>> import pyexcel.ext.text as text
>>> content = [
...     ["Column 1", "Column 2", "Column 3"],
...     [1, 2, 3],
...     [4, 5, 6],
...     [7, 8, 9]
... ]
>>> sheet = pe.Sheet(content)
>>> sheet
Sheet Name: pyexcel
--------  --------  --------
Column 1  Column 2  Column 3
1         2         3
4         5         6
7         8         9
--------  --------  --------
>>> sheet.name_columns_by_row(0)
>>> sheet
Sheet Name: pyexcel
  Column 1    Column 2    Column 3
----------  ----------  ----------
         1           2           3
         4           5           6
         7           8           9
>>> text.TABLEFMT = "grid"
>>> sheet
Sheet Name: pyexcel
+------------+------------+------------+
|   Column 1 |   Column 2 |   Column 3 |
+============+============+============+
|          1 |          2 |          3 |
+------------+------------+------------+
|          4 |          5 |          6 |
+------------+------------+------------+
|          7 |          8 |          9 |
+------------+------------+------------+
>>> multiple_sheets = {
...      'Sheet 1':
...          [
...              [1.0, 2.0, 3.0],
...              [4.0, 5.0, 6.0],
...              [7.0, 8.0, 9.0]
...          ],
...      'Sheet 2':
...          [
...              ['X', 'Y', 'Z'],
...              [1.0, 2.0, 3.0],
...              [4.0, 5.0, 6.0]
...          ],
...      'Sheet 3':
...          [
...              ['O', 'P', 'Q'],
...              [3.0, 2.0, 1.0],
...              [4.0, 3.0, 2.0]
...          ]
...  }
>>> book = pe.Book(multiple_sheets)
>>> text.TABLEFMT = "mediawiki"
>>> book.save_as("myfile.mediawiki")
>>> myfile = open("myfile.mediawiki")
>>> print(myfile.read())
Sheet Name: Sheet 1
{| class="wikitable" style="text-align: left;"
|+ <!-- caption -->
|-
| align="right"| 1 || align="right"| 2 || align="right"| 3
|-
| align="right"| 4 || align="right"| 5 || align="right"| 6
|-
| align="right"| 7 || align="right"| 8 || align="right"| 9
|}
Sheet Name: Sheet 2
{| class="wikitable" style="text-align: left;"
|+ <!-- caption -->
|-
| X   || Y   || Z
|-
| 1.0 || 2.0 || 3.0
|-
| 4.0 || 5.0 || 6.0
|}
Sheet Name: Sheet 3
{| class="wikitable" style="text-align: left;"
|+ <!-- caption -->
|-
| O   || P   || Q
|-
| 3.0 || 2.0 || 1.0
|-
| 4.0 || 3.0 || 2.0
|}
<BLANKLINE>

Dependencies

  • tabulate

Project details


Download files

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

Source Distribution

pyexcel-text-0.1.1.zip (8.3 kB view details)

Uploaded Source

File details

Details for the file pyexcel-text-0.1.1.zip.

File metadata

  • Download URL: pyexcel-text-0.1.1.zip
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyexcel-text-0.1.1.zip
Algorithm Hash digest
SHA256 f760706eda09331c863696b62a14ba0a96ef0c07d1bf983198291f0d19d53491
MD5 818c0c77068368d9345e844808c9bdae
BLAKE2b-256 b68377b4a737badb575c4e7314fd7e9ffaa074719702d9c46709f77e4ac4ce48

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page