Accessing and editing embedded excel files?
Hi Steve,
I'm wondering if there's way to access the embedded excel file in charts. I thought it would be: prs.slides[0].shapes[0].chart._workbook
Is this the right object? It seems that I can open it using xlsxwriter but somehow I can't write anything to it and save it back to the pptx file.
Thanks a lot for your help!
No, you need to go to the part level because the Excel is in a different part (EmbeddedXlsxPart or something). Step-by-step it's like this:
chart_part = chart.part
chart_workbook = chart_part.chart_workbook
xlsx_part = chart_workbook.xlsx_part
From there you have the methods on Part: https://github.com/scanny/python-pptx/blob/master/pptx/opc/package.py#L169
So maybe save xlsx_part.blob as file something.xlsx and then read it. You could also pop the blob into a StringIO object and then maybe pass it into openpyxl or something.