Using openpyxl 3.0.6 to make a sheet and everything is fine until the code adds a chart to the sheet. When I comment out this_sheet.add_chart(chart, cell_loc)
the workbook will open no problem but without the chart. LibreOffice Calc will open the workbook without any problem. Has anyone else had to deal with this or is there something wrong with the chart code?
I have looked at StackOverflow post but this does not seem to be my issue.
chart = LineChart()
chart.smooth = False
chart.title = "Change From 2017"
chart.style = 12
chart.y_axis.title = "Delta"
chart.y_axis.crossAx = 500
chart.x_axis = TextAxis(crossAx=100)
chart.y_axis.scaling.min = 0.00
chart.y_axis.scaling.max = 0.12
chart.legend = None
chart.x_axis.delete = False
chart.y_axis.delete = False
#chart.title.delete = False
chart.add_data(data, from_rows=True)
chart.set_categories(cats)
s1 = chart.series[0]
s1.smooth = False
s1.marker.symbol = "triangle"
s1.marker.graphicalProperties.solidFill = "FF0000" # Marker filling
s1.marker.graphicalProperties.line.solidFill = "FF0000" # Marker outline
s1.graphicalProperties.line.noFill = True
cell_loc = str("B"+ str(this_sheet.max_row+5))
chart.height = 12 # default is 7.5
chart.width = 65 # default is 15
this_sheet.add_chart(chart, cell_loc)
When Excel does "recover" the file there is no chart and has a Repair report -
Removed Part: /xl/drawings/drawing5.xml part. (Drawing shape) error182120_03.xmlErrors were detected in file 'D:\01_SSI_Projects\2020_Projects\20247\resave_report.xlsx'Removed Part: /xl/drawings/drawing1.xml part. (Drawing shape)Removed Part: /xl/drawings/drawing2.xml part. (Drawing shape)Removed Part: /xl/drawings/drawing3.xml part. (Drawing shape)Removed Part: /xl/drawings/drawing4.xml part. (Drawing shape)Removed Part: /xl/drawings/drawing5.xml part. (Drawing shape)
UPDATE I commented out 1 line:
#chart.y_axis.crossAx = 500
Excel no longer gives an error. The data type in the y_axis is NumericAxis so that was the problem. This comes from increment of x and y axis ticks