AttributeError: 'str' object has no attribute 'to_tree' when saving
Using this code
wb = load_workbook('path/to/file')
data = wb["SHEET NAME"]
data.cell(1, 2).value = "value"
wb.save('path/to/file')
I get this error and the file becomes corrupted and cannot be opened
AttributeError: 'str' object has no attribute 'to_tree'
Here is the stack trace
File "C:\Users\abhay\Desktop\Repos\star-data-anal\main.py", line 45, in <module>
wb.save('C:/users/abhay/Downloads/Internship_Telescope_Data.xlsx')
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\workbook\workbook.py", line 407, in save
save_workbook(self, filename)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook
writer.save()
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\writer\excel.py", line 275, in save
self.write_data()
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\writer\excel.py", line 78, in write_data
self._write_charts()
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\writer\excel.py", line 124, in _write_charts
self._archive.writestr(chart.path[1:], tostring(chart._write()))
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\chart\_chart.py", line 134, in _write
return cs.to_tree()
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\chart\chartspace.py", line 193, in to_tree
tree = super(ChartSpace, self).to_tree()
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 154, in to_tree
node = obj.to_tree(child_tag)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 154, in to_tree
node = obj.to_tree(child_tag)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\chart\plotarea.py", line 135, in to_tree
return super(PlotArea, self).to_tree(tagname)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 146, in to_tree
for node in nodes:
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\sequence.py", line 105, in to_tree
el = v.to_tree(namespace=namespace)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\chart\_chart.py", line 107, in to_tree
return super(ChartBase, self).to_tree(tagname, idx)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 146, in to_tree
for node in nodes:
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\sequence.py", line 39, in to_tree
el = v.to_tree(tagname, idx)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\chart\series.py", line 170, in to_tree
return super(Series, self).to_tree(tagname)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 154, in to_tree
node = obj.to_tree(child_tag)
File "C:\Users\abhay\AppData\Local\Programs\Python\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 154, in to_tree
node = obj.to_tree(child_tag)
AttributeError: 'str' object has no attribute 'to_tree'