Skip to content

Commit 034ef8d

Browse files
committed
Merge pull request #7565 from neirbowj/openpyxl2_issue7177
ENH: Implement _Openpyxl2Writer for pandas.io.excel
2 parents feb6870 + 99d8835 commit 034ef8d

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
@@ -2058,7 +2058,12 @@ files if `Xlsxwriter`_ is not available.
20582058
.. _xlwt: http://www.python-excel.org
20592059

20602060
To specify which writer you want to use, you can pass an engine keyword
2061-
argument to ``to_excel`` and to ``ExcelWriter``.
2061+
argument to ``to_excel`` and to ``ExcelWriter``. The built-in engines are:
2062+
2063+
- `'openpyxl`': This includes stable support for OpenPyxl 1.6.1 up to but
2064+
not including 2.0.0, and experimental support for OpenPyxl 2.0.0 and later.
2065+
- `'xlsxwriter'`
2066+
- `'xlwt'`
20622067

20632068
.. code-block:: python
20642069

doc/source/v0.15.0.txt

+6
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,12 @@ Enhancements
738738

739739

740740

741+
- Added experimental compatibility with openpyxl v2. The ``DataFrame.to_excel``
742+
method ``engine`` keyword now recognizes ``openpyxl1`` and ``openpyxl2``
743+
which will explicitly require openpyxl v1 and v2 respectively, failing if
744+
the requested version is not available. The ``openpyxl`` engine is a now a
745+
meta-engine that automatically uses whichever version of openpyxl is
746+
installed. (:issue:`7177`)
741747

742748

743749

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)