Embed excel file as an excel-alike table into sphinx documentation.
Project description
sphinxcontrib-excel-table
The sphinxcontrib-excel-table 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 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
Installation
You can install it via pip:
$ pip install sphinxcontrib-excel-table
or install it from source code:
$ git clone https://github.com/hackerain/sphinxcontrib-excel-table.git
$ cd sphinxcontrib-excel-table
$ python setup.py install
Setup
Add sphinxcontrib.excel_table to your conf.py file:
extensions = ['sphinxcontrib.excel_table']
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; print sphinxcontrib.excel_table"
for example in Mac:
$ INSTALLATION_PATH=/Library/Python/2.7/site-packages/sphinxcontrib/excel_table/
$ 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:
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 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 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
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
File details
Details for the file sphinxcontrib-excel-table-1.0.8.tar.gz
.
File metadata
- Download URL: sphinxcontrib-excel-table-1.0.8.tar.gz
- Upload date:
- Size: 159.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/36.3.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed4b6a8b831b59d621a81e696bc8ac1ecaa5788f773985f95e318f39ac5fe9e0 |
|
MD5 | 9cec27b5ba7f8750209f823d5e3d5733 |
|
BLAKE2b-256 | bfa5337fefe9099bb4a54303fad28c3b5da3138b40d0290f46107508ebb4fa08 |