openpyxl icon indicating copy to clipboard operation
openpyxl copied to clipboard

Excel Charts Corrupted After Open/Save with Openpyxl Library

Open maxkuzkin opened this issue 6 months ago • 3 comments

Description:

When using the Openpyxl library to open and save an Excel file containing charts (please note multiple tabs in the file to simplify case-by-case navigation), the charts become corrupted in the resulting file.

Steps to Reproduce:

  1. Take an Excel file (source-file-with-charts.xlsx) with charts.
  2. Use the following Python script to open and save the workbook:
import openpyxl

# Load the source workbook
wb = openpyxl.load_workbook('./source-file-with-charts.xlsx')

# Save the workbook to a new file
wb.save('./target-file-with-charts.xlsx')

# Close the workbook
wb.close()
  1. Open the resulting Excel file (target-file-with-charts.xlsx).

Expected Result:

The charts in the resulting file (target-file-with-charts.xlsx) should appear the same as in the source file (source-file-with-charts.xlsx).

Actual Result:

The charts in the resulting file (target-file-with-charts.xlsx) are corrupted.

Common Corruptions:

Some of the common corruptions include:

  1. Rounded corners are added to charts when they were not needed.
  2. Font sizes and colors change to different values.
  3. Chart backgrounds and colors change to different values.
  4. Certain chart types (like maps) disappear entirely.

Attachments:

Examples from the file (source and corrupted target):

Case 1 image

Case 2 image

Case 3 image

Case 4 image

Case 5 image

Case 6 image

Library Version

This issue has been present in Openpyxl for many years, but I haven't had the chance to report it until now. The version used to reproduce this problem is:

% pip info
Name: openpyxl
Version: 3.1.5
Summary: A Python library to read/write Excel 2010 xlsx/xlsm files
Home-page: https://openpyxl.readthedocs.io
Author: See AUTHORS
Author-email: [email protected]
License: MIT

maxkuzkin avatar Aug 21 '24 22:08 maxkuzkin