Skip to content

Commit 99d8835

Browse files
committed
ENH/TST/DOC: Implement experimental io.excel._Openpyxl2Writer
1 parent 631e0ba commit 99d8835

File tree

5 files changed

+558
-37
lines changed

5 files changed

+558
-37
lines changed

doc/source/io.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,12 @@ files if `Xlsxwriter`_ is not available.
20092009
.. _xlwt: http://www.python-excel.org
20102010

20112011
To specify which writer you want to use, you can pass an engine keyword
2012-
argument to ``to_excel`` and to ``ExcelWriter``.
2012+
argument to ``to_excel`` and to ``ExcelWriter``. The built-in engines are:
2013+
2014+
- `'openpyxl`': This includes stable support for OpenPyxl 1.6.1 up to but
2015+
not including 2.0.0, and experimental support for OpenPyxl 2.0.0 and later.
2016+
- `'xlsxwriter'`
2017+
- `'xlwt'`
20132018

20142019
.. code-block:: python
20152020

doc/source/v0.15.0.txt

+6
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,12 @@ Enhancements
673673

674674

675675

676+
- Added experimental compatibility with openpyxl v2. The ``DataFrame.to_excel``
677+
method ``engine`` keyword now recognizes ``openpyxl1`` and ``openpyxl2``
678+
which will explicitly require openpyxl v1 and v2 respectively, failing if
679+
the requested version is not available. The ``openpyxl`` engine is a now a
680+
meta-engine that automatically uses whichever version of openpyxl is
681+
installed. (:issue:`7177`)
676682

677683

678684

pandas/compat/openpyxl_compat.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@
1010
stop_ver = '2.0.0'
1111

1212

13-
def is_compat():
14-
"""Detect whether the installed version of openpyxl is supported.
13+
def is_compat(major_ver=1):
14+
"""Detect whether the installed version of openpyxl is supported
1515
16+
Parameters
17+
----------
18+
ver : int
19+
1 requests compatibility status among the 1.x.y series
20+
2 requests compatibility status of 2.0.0 and later
1621
Returns
1722
-------
1823
compat : bool
19-
``True`` if openpyxl is installed and is between versions 1.6.1 and
20-
2.0.0, ``False`` otherwise.
24+
``True`` if openpyxl is installed and is a compatible version.
25+
``False`` otherwise.
2126
"""
2227
import openpyxl
2328
ver = LooseVersion(openpyxl.__version__)
24-
return LooseVersion(start_ver) <= ver < LooseVersion(stop_ver)
29+
if major_ver == 1:
30+
return LooseVersion(start_ver) <= ver < LooseVersion(stop_ver)
31+
elif major_ver == 2:
32+
return LooseVersion(stop_ver) <= ver
33+
else:
34+
raise ValueError('cannot test for openpyxl compatibility with ver {0}'
35+
.format(major_ver))

0 commit comments

Comments
 (0)