Skip to content

fuhrysteve/pyexcel-text

 
 

Repository files navigation

pyexcel-text

image

image

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

>>> 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;" -| 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 class="wikitable" style="text-align: left;" -| X || Y || Z 1.0 || 2.0 || 3.0 4.0 || 5.0 || 6.0 class="wikitable" style="text-align: left;" -| O || P || Q 3.0 || 2.0 || 1.0 4.0 || 3.0 || 2.0 |} <BLANKLINE>

>>> myfile.close() >>> import os >>> os.unlink("myfile.mediawiki")

Dependencies

  • tabulate

About

It is a plugin to pyexcel and provides the capbility to present and write data in text fromats

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.6%
  • Other 1.4%