theorchard / openpyxl

Other
54 stars 17 forks source link

Excel Charts Corrupted After Open/Save with Openpyxl Library #62

Open maxkuzkin opened 3 weeks ago

maxkuzkin commented 3 weeks ago

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: charlie.clark@clark-consulting.eu
License: MIT
maxkuzkin commented 3 weeks ago

I've also reported this issue at https://foss.heptapod.net/openpyxl/openpyxl/-/issues/2220. I'm not sure which issue tracker is the main one for openpyxl, so sorry for the duplicate. You can close either one.