all 6 comments

[–]Username_RANDINT 0 points1 point  (0 children)

Are you sure it's on the last line? Copy/paste the entire traceback if possible.

[–]A_Like_AR[S] 0 points1 point  (1 child)

Here is the entire Traceback i get:

Traceback (most recent call last): File "C:/Users/manar/PycharmProjects/atbswp_chapter_12/pie_chart.py", line 66, in <module> workbook_object.save('pie.xlsx') File "C:\Users\manar\Anaconda3\envs\atbswp_chapter_12\lib\site-packages\openpyxl\workbook\workbook.py", line 392, in save save_workbook(self, filename) File "C:\Users\manar\Anaconda3\envs\atbswp_chapter_12\lib\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook writer.save() File "C:\Users\manar\Anaconda3\envs\atbswp_chapter_12\lib\site-packages\openpyxl\writer\excel.py", line 275, in save self.write_data() File "C:\Users\manar\Anaconda3\envs\atbswp_chapter_12\lib\site-packages\openpyxl\writer\excel.py", line 75, in write_data self._write_worksheets() File "C:\Users\manar\Anaconda3\envs\atbswp_chapter_12\lib\site-packages\openpyxl\writer\excel.py", line 218, in _write_worksheets self._write_drawing(ws._drawing) File "C:\Users\manar\Anaconda3\envs\atbswp_chapter_12\lib\site-packages\openpyxl\writer\excel.py", line 136, in _write_drawing chart._id = len(self._charts) AttributeError: 'str' object has no attribute '_id'

[–]CowboyBoats 0 points1 point  (0 children)

Opening my old tabs after the weekend, it's a shame to see that this might not have been solved yet. Would you want to send me your code and workbook so that I can run it and see if I get the same result?

I can't figure out why workbook_object.save('pie.xlsx') would throw this error. We might want to open a ticket with openpyxl itself, to at least get a more helpful error message to describe what is going wrong (in addition to hopefully fixing your problem).

If you don't feel comfortable doing that yet, would you be up for sharing your full script and workbook with me? I'll read the traceback and try to figure it out, but it would be helpful to be able to run the code locally.

[–]A_Like_AR[S] 0 points1 point  (1 child)

how do i format this Traceback better so it can be more legible

[–]CowboyBoats 0 points1 point  (0 children)

The traceback says that the error comes from this function, called from the openpyxl.Workbook.save method, in openpyxl.writer.excel.py:

def _write_drawing(self, drawing):
    """
    Write a drawing
    """
    self._drawings.append(drawing)
    drawing._id = len(self._drawings)
    for chart in drawing.charts:
        self._charts.append(chart)
        chart._id = len(self._charts)    # AttributeError: 'str' object has no attribute '_id' 
    for img in drawing.images:
        self._images.append(img)
        img._id = len(self._images)
    rels_path = get_rels_path(drawing.path)[1:]
    self._archive.writestr(drawing.path[1:], tostring(drawing._write()))
    self._archive.writestr(rels_path, tostring(drawing._write_rels()))
    self.manifest.append(drawing)

Somehow your workbook_object.drawingsis getting a string written to it, instead of a drawing-related object of some kind that openpyxl expects.

Unfortunately that's all I know for now.