Unable to save wb with 3D bar chart from openpyxl example

Issue #1237 new
jeremy turner
created an issue


I have been using openpyxl to edit xlsx files that have charts. I recently came across a file that has a 3D Bar Chart in it. When i tried to save the workbook, openpyxl gave me an error:

expected <class 'openpyxl.chart._3d.View3D'>

Looking into this i noticed that chart.view3D was of type:


I thought maybe this was an issue with the file i was working on, so i looked up how to use 3d bar charts in the openpyxl docs. I followed the instructions on how to build a simple 3D bar chart and, when trying to save that test workbook, i got the same error:

expected <class 'openpyxl.chart._3d.View3D'>

is there a solution for this issue or a ticket already submitted?

My current working solution is to copy the series, category, title,legend, etc from the 3D bar chart and copy them into 2d bar chart object that i use to replace the 3d bar chart.

I have attached the test 3d bar chart file that simply load and then try to save. Here is the code for the test 3d bar chart that produces the error:

from openpyxl import Workbook
from openpyxl.chart import (

wb = Workbook()
ws = wb.active

rows = [
    (None, 2013, 2014),
    ("Apples", 5, 4),
    ("Oranges", 6, 2),
    ("Pears", 8, 3)

for row in rows:

data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=4)
titles = Reference(ws, min_col=1, min_row=2, max_row=4)
chart = BarChart3D()
chart.title = "3D Bar Chart"
chart.add_data(data=data, titles_from_data=True)

ws.add_chart(chart, "E5")

Comments (3)

  1. CharlieC

    Thanks for the report and the sample file. I suspect openpyxl is having trouble reading the source of the chart and mapping it to the correct openpyxl class.

  2. Log in to comment