Skip to main content

Embed excel file as an excel-alike table into sphinx documentation.* Forked with extended support for html in columns.

Project description

sphinxcontrib-excel-table-plus

The sphinxcontrib-excel-table-plus extension is to render an excel file as an excel-alike table in Sphinx documentation.

This contrib is inspired by sphinxcontrib-excel, which uses pyexcel and handsontable to do the work, but the sphinxcontrib-excel-table-plus will instead use openpyxl and handsontable, mainly to support the following features:

  • merged cell

  • display specific sheet

  • display specific section in one sheet

  • display specific rows in one sheet

  • (plus) added support to render html in columns

Installation

You can install it via pip:

$ pip install sphinxcontrib-excel-table-plus

or install it from source code:

$ git clone https://github.com/emerge-ehri/sphinxcontrib-excel-table-plus.git
$ cd sphinxcontrib-excel-table-plus
$ python setup.py install

Setup

Add sphinxcontrib.excel_table_plus to your conf.py file:

extensions = ['sphinxcontrib.excel_table_plus']

And you need to copy the resource files to your sphinx source directory, the resource files has been installed to your python system path if you install the package via pip, you can copy them from the installation path. You can get the installation path through:

python -c "import sphinxcontrib.excel_table_plus; print sphinxcontrib.excel_table_plus"

for example in Mac:

$ INSTALLATION_PATH=/Library/Python/2.7/site-packages/sphinxcontrib/excel_table_plus/
$ cp $INSTALLATION_PATH/resources/_templates/layout.html path/to/your/project/_templates/
$ cp $INSTALLATION_PATH/resources/_static/handsontable.full.min.js path/to/your/project/_static/
$ cp $INSTALLATION_PATH/resources/_static/handsontable.full.min.css path/to/your/project/_static/

or you can copy the resource files from source code directly.

Usage

Here is the syntax to present your excel file in sphinx documentation:

.. excel-table::
   :file: path/to/file.xlsx

This will translate to:

https://raw.githubusercontent.com/emerge-ehri/sphinxcontrib-excel-table-plus/master/sphinx_excel_table.png

As you can see, it supports merged cells, and this is the mainly goal this contrib will achieve, because other sphinxcontrib excel extensions don’t support this feature, and are not convenient to implement it. The sphinxcontrib-excel-table-plus can do this easily using openpyxl library.

Options

This sphinxcontrib provides the following options:

file (required)

Relative path (based on document) to excel documentation. Note that as openpyxl only supports excel xlsx/xlsm/xltx/xltm files, so this contrib doesn’t support other old excel file formats like xls.

.. excel-table::
   :file: path/to/file.xlsx

sheet (optional)

Specify the name of the sheet to dispaly, if not given, it will default to the first sheet in the excel file.

.. excel-table::
   :file: path/to/file.xlsx
   :sheet: Sheet2

Note this contrib can only display one sheet in one excel-table-plus directive, but you can display different sheet in one excel in different directives.

rows (optional)

Specify the row range of one sheet do display, the default is to display all rows in one sheet, if you use this option, remember to specify a range seperated by a colon.

.. excel-table::
   :file: path/to/file.xlsx
   :rows: 1:10

selection (optional)

Selection defines from and to the selection reaches. If value is not defined, the whole data from sheet is taken into table. And if selection is used, it must specify the from and to range seperated by a colon.

.. excel-table::
   :file: path/to/file.xlsx
   :selection: A1:D10

overflow (optional)

Prevents table to overlap outside the parent element. If ‘horizontal’ option is chosen then table will appear horizontal scrollbar in case where parent’s width is narrower then table’s width. The default is ‘horizontal’, if you want to disable this feature, you can set false to this option.

.. excel-table::
   :file: path/to/file.xlsx
   :overflow: false

tablewidth (optional)

Defines spreadsheet width in pixels. Accepts number, string (that will be converted to a number). The underlying spreadsheet implementation defaults to a width of 600px, you can change the value here if needed.

.. excel-table::
   :file: path/to/file.xlsx
   :tablewidth: 1000

colwidths (optional)

Defines column widths in pixels. Accepts number, string (that will be converted to a number), array of numbers (if you want to define column width separately for each column) or a function (if you want to set column width dynamically on each render). The default value is undefined, means the width will be determined by the parent elements.

.. excel-table::
   :file: path/to/file.xlsx
   :colwidths: 100

row_header (optional)

To decide whether to show the row header, the default is true, means to show the row header, you can set this to false to disable the row header.

.. excel-table::
   :file: path/to/file.xlsx
   :row_header: false

col_header (optional)

To decide whether to show the col header, the default is true, means to show the col header, you can set this to false to disable the col header.

.. excel-table::
   :file: path/to/file.xlsx
   :col_header: false

Change log

1.0.0

  • Refactor the code to one folder

1.0.1

  • Add margin bottom to excel table div

1.0.2

  • Add row_header and col_header option to control whether to show the headers

1.0.3

  • Fix bug when openpyxl upgrade to 2.5.2

1.0.4

  • Add python 3 support

1.0.6

  • Fix bug when calls to the same file multiple times chunks the table together

  • Fix bug date NameError when running in Python 3

  • Use the new merged_cells interface of openpyxl

1.0.7

  • Adds the ability to set the table width

1.0.8

  • Fix REAEME about table width usage

1.0.8.1

  • Added html renderer to columns. based on fork from original sphinxcontrib-excel-table project.

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

sphinxcontrib-excel-table-plus-1.0.8.1.tar.gz (160.2 kB view details)

Uploaded Source

File details

Details for the file sphinxcontrib-excel-table-plus-1.0.8.1.tar.gz.

File metadata

  • Download URL: sphinxcontrib-excel-table-plus-1.0.8.1.tar.gz
  • Upload date:
  • Size: 160.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.0

File hashes

Hashes for sphinxcontrib-excel-table-plus-1.0.8.1.tar.gz
Algorithm Hash digest
SHA256 f3b4e91713e88bee57eb13fc90157ad23ac90ddc6406b137f602651db461591a
MD5 78e7567953f139ee805d0fe0ef8ee874
BLAKE2b-256 f7b7779dd20e30cb7c4b3517307ddb014ddd80d23fcc9240e80018abf984160e

See more details on using hashes here.

Supported by

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