Unable to save wb with 3D bar chart from openpyxl example
Created originally on Bitbucket by USN_SHIPWRECK (jeremy turner)
Hello,
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:
#!python
expected <class 'openpyxl.chart._3d.View3D'>
Looking into this i noticed that chart.view3D was of type:
#!python
openpyxl.descriptors.base.Typed
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:
#!python
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:
#!python
from openpyxl import Workbook
from openpyxl.chart import (
Reference,
Series,
BarChart3D,
)
wb = Workbook()
ws = wb.active
rows = [
(None, 2013, 2014),
("Apples", 5, 4),
("Oranges", 6, 2),
("Pears", 8, 3)
]
for row in rows:
ws.append(row)
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)
chart.set_categories(titles)
ws.add_chart(chart, "E5")
wb.save("bar3d.xlsx")
Attachments: 3d_bar_chart_test.xlsx