Skip to main content

A plugin to pyexcel and provides the capability to present and write data in text formats

Project description

https://api.travis-ci.org/pyexcel/pyexcel-text.png https://codecov.io/github/pyexcel/pyexcel-text/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”

  • “html”

Usage

Simple

>>> import pyexcel as pe
>>> content = [
...     ["Column 1", "Column 2", "Column 3"],
...     [1, 2, 3],
...     [4, 5, 6],
...     [7, 8, 9]
... ]
>>> sheet = pe.Sheet(content)
>>> print(sheet.simple)
pyexcel sheet:
--------  --------  --------
Column 1  Column 2  Column 3
1         2         3
4         5         6
7         8         9
--------  --------  --------
>>> sheet.name_columns_by_row(0)
>>> print(sheet.simple)
pyexcel sheet:
  Column 1    Column 2    Column 3
----------  ----------  ----------
         1           2           3
         4           5           6
         7           8           9

Grid

>>> print(sheet.grid)
pyexcel sheet:
+------------+------------+------------+
|   Column 1 |   Column 2 |   Column 3 |
+============+============+============+
|          1 |          2 |          3 |
+------------+------------+------------+
|          4 |          5 |          6 |
+------------+------------+------------+
|          7 |          8 |          9 |
+------------+------------+------------+

Mediawiki

>>> 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)
>>> book.save_as("myfile.mediawiki")
>>> myfile = open("myfile.mediawiki")
>>> print(myfile.read())
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 2:
{| class="wikitable" style="text-align: left;"
|+ <!-- caption -->
|-
| X   || Y   || Z
|-
| 1.0 || 2.0 || 3.0
|-
| 4.0 || 5.0 || 6.0
|}
Sheet 3:
{| class="wikitable" style="text-align: left;"
|+ <!-- caption -->
|-
| O   || P   || Q
|-
| 3.0 || 2.0 || 1.0
|-
| 4.0 || 3.0 || 2.0
|}
>>> myfile.close()

Html

>>> book.save_as("myfile.html")
>>> myfile = open("myfile.html")
>>> print(myfile.read()) # doctest: +SKIP
Sheet 1:
<table>
<tr><td style="text-align: right;">1</td><td style="text-align: right;">2</td><td style="text-align: right;">3</td></tr>
<tr><td style="text-align: right;">4</td><td style="text-align: right;">5</td><td style="text-align: right;">6</td></tr>
<tr><td style="text-align: right;">7</td><td style="text-align: right;">8</td><td style="text-align: right;">9</td></tr>
</table>
Sheet 2:
<table>
<tr><td>X  </td><td>Y  </td><td>Z  </td></tr>
<tr><td>1.0</td><td>2.0</td><td>3.0</td></tr>
<tr><td>4.0</td><td>5.0</td><td>6.0</td></tr>
</table>
Sheet 3:
<table>
<tr><td>O  </td><td>P  </td><td>Q  </td></tr>
<tr><td>3.0</td><td>2.0</td><td>1.0</td></tr>
<tr><td>4.0</td><td>3.0</td><td>2.0</td></tr>
</table>

Please note tabulate 0.7.7 gives an extra tbody tag around tr tag.

Dependencies

  • tabulate

Change log

0.2.6 - 19.06.2017

Updated:

  1. Support pyexcel v0.5.0. Plugin interface updated to Renderer

  2. removed deprecated save_as and save_to_memory functions

0.2.5 - 28.10.2016

Updated:

  1. Support pyexcel v0.4.0

0.2.4 - 28.10.2016

Added:

  1. support pyexcel v0.3.0

0.2.3 - 14.07.2016

Added:

  1. json format: serialize date and datetime

Updated:

  1. if a sheet has row_names, its json output become records(a list of dictionary) instead of a dictionary of row name vs the rest of row values.

0.2.2 - 01.06.2016

  1. quick bug fix, see issue #27

0.2.1 - 01.06.2016

  1. compactibility with pyexcel-io 0.2.0 and pyexcel 0.2.2

0.2.0 - 23.04.2016

It is a complete re-write of the whole extension.

Added

  1. html support

  2. support pyexcel 0.2.0’s generator output

  3. pypy and pypy3 in test targets

  4. support file stream and dot notation, e.g. pyexcel.Sheet.rst will return rst text representation of it.

Updated

  1. #8, write_header as an option(False) to disable header writing

  2. the json output of multiple sheet book will be sorted by its sheet names.

  3. No longer, pyexcel-text is pyexcel-io plugin but pyexcel.sources plugin.

0.1.1 - 30.01.2016

Updated

  1. #2, fix a typo in setup.py

0.1.0 - 17.01.2016

Updated

  1. support pyexcel 0.2.0

0.0.3 - 12.06.2015

Updated

  1. #1, align api interface

    with other pyexcel plugins, e.g. save_as, save_book_as

0.0.2 - 30.11.2014

Updated

  1. support pyexcel 0.0.9

0.0.` - 20.11.2014

Initial release

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.2.6.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyexcel_text-0.2.6-py2-none-any.whl (7.9 kB view details)

Uploaded Python 2

File details

Details for the file pyexcel-text-0.2.6.tar.gz.

File metadata

  • Download URL: pyexcel-text-0.2.6.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyexcel-text-0.2.6.tar.gz
Algorithm Hash digest
SHA256 8bab2bf0f199119b5296c21ef7589d2603d4bf186a29f33853aeea93b1e49703
MD5 6094228017a763b85afe877f520ebc37
BLAKE2b-256 438712bb8fe137ba3954446a80f9c603340b72bc157ffdca534ca3febc4ef3bf

See more details on using hashes here.

File details

Details for the file pyexcel_text-0.2.6-py2-none-any.whl.

File metadata

File hashes

Hashes for pyexcel_text-0.2.6-py2-none-any.whl
Algorithm Hash digest
SHA256 540d06f9a04005f8087dcac366bf84ca945c1b52f0bea0b0b829148720b7000f
MD5 9e59a185e5bec095703880f17d21581f
BLAKE2b-256 024cda77acfdfd14312fd466a5b1582609bcfda23d0136d624bf27a52900d637

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