Public bug reported:

Package: python3-openpyxl
Version: 3.1.2+dfsg-6

When using the openpyxl library to create or edit MS Excel workbooks,
the generated file cannot be opened without an error message:

"We found a problem with some content in [excel-file]..."

Minimal example code:
 
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.title = "Sheet"
ws["A1"] = "Header"
ws["A2"] = "Some Data"
wb.save("simple_example.xlsx")

The problem occurs when using the library installed from the Ubuntu
package.

In a virtual environment the same openpyxl version 3.1.2 works fine.

Diagnosis:

When comparing the content of the generated Excel files, it turns out
that the content of some of the generated XML files in in the wrong
order, e.g. docProps/core.xml

Correct XML (pip installed):

<cp:coreProperties
xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-
properties" xmlns:dc="http://purl.org/dc/elements/1.1/";
xmlns:dcterms="http://purl.org/dc/terms/";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"><dc:creator>openpyxl</dc:creator><dcterms:created
xsi:type="dcterms:W3CDTF">2026-06-03T10:52:25Z</dcterms:created><dcterms:modified
xsi:type="dcterms:W3CDTF">2026-06-03T10:52:25Z</dcterms:modified></cp:coreProperties>

Incorrect XML (Ubuntu package):

<cp:coreProperties
xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-
properties"><dc:creator
xmlns:dc="http://purl.org/dc/elements/1.1/";>openpyxl</dc:creator><dcterms:created
xmlns:dcterms="http://purl.org/dc/terms/";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:type="dcterms:W3CDTF">2026-06-03T13:39:02+00:00Z</dcterms:created><dcterms:modified
xmlns:dcterms="http://purl.org/dc/terms/";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:type="dcterms:W3CDTF">2026-06-03T13:39:02+00:00Z</dcterms:modified></cp:coreProperties>

It turns out that this behavior is caused by the lxml library, which is
by default used when installed. The pip installed openpyxl in the
virtual environment depends only on et_xmlfile, which provides the
necessary functionality for writing XML files instead of lxml.

The Ubuntu python3-openpyxl package depends on both libraries:

Depends: python3-et-xmlfile, python3:any, python3-lxml

So apparently the faulty python3-lxml cannot easily be removed.

It is possible though to force openpyxl to ignore lxml by setting the
environment variable 'OPENPYXL_LXML=False'

After this setting the wrong line order in the XML files does not occur.

Unfortunately there is a secondary error in the Ubuntu package.

The upstream maintainer added a patch python3p12_compat.patch which aims
to improve Python 3.12 compatibility by using newer time/date functions.
Unfortunately this changes the time format used in docProps/core.xml
from

"2026-06-03T10:52:25Z"

to

"2026-06-03T13:39:25+00:00Z"

which also caused Excel to show the same error message when opening the
file.

Upstream has updated openpyxl to a newer release, which does not contain
the Python 3.12 compatibility patch anymore.

I have not further investigated why lxml outputs the lines of the XML
file in a wrong order.

ProblemType: Bug
DistroRelease: Ubuntu 24.04
Package: python3-openpyxl 3.1.2+dfsg-6
ProcVersionSignature: Ubuntu 6.8.0-117.117-generic 6.8.12
Uname: Linux 6.8.0-117-generic x86_64
ApportVersion: 2.28.1-0ubuntu3.8
Architecture: amd64
CasperMD5CheckResult: unknown
CloudArchitecture: x86_64
CloudBuildName: server
CloudID: openstack
CloudName: openstack
CloudPlatform: openstack
CloudSerial: 20260307
CloudSubPlatform: metadata (http://169.254.169.254)
Date: Wed Jun  3 19:43:59 2026
PackageArchitecture: all
RebootRequiredPkgs: Error: path contained symlinks.
SourcePackage: openpyxl
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: openpyxl (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug cloud-image noble

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2155189

Title:
  openpyxl generates invalid Excel files

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/openpyxl/+bug/2155189/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to