Python Forum

Full Version: Is there any way to transfer charts generated from excel to powerpoint?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I modified some code that i found online which uses pandas and xlsxwriter to read an excel sheet and generate a chart. Right now it inserts the generated chart into the excel sheet, i want to know if it is possible to insert the chart into a powerpoint presentation.

my dataset:
[Image: F4KNEBp.png]

code snippet:

import pandas as pd

excel_file = 'scoresonly.xlsx'
movies = pd.read_excel(excel_file)

df1 = movies['Title']
df2 = movies['IMDB Score']

writer = pd.ExcelWriter( excel_file, engine='xlsxwriter')

# Convert the dataframe to an XlsxWriter Excel object.
df1.to_excel(writer, sheet_name='Sheet1', index=False)
df2.to_excel(writer, sheet_name='Sheet1', startcol=1, index=False)

# Get the xlsxwriter workbook and worksheet objects.
workbook  = writer.book
worksheet = writer.sheets['Sheet1']

# Create a chart object.
chart = workbook.add_chart({'type': 'column'})

# Configure the series of the chart from the dataframe data.
chart.add_series({
    'categories': ['Sheet1', 1, 0, len(df1), 0],
    'values':     ['Sheet1', 1, 1, len(df2), 1]})

# Insert the chart into the worksheet.
worksheet.insert_chart('D2', chart)

# Close the Pandas Excel writer and output the Excel file.
writer.save()
final result:

[Image: SX4Zv5z.png]
Found a solution:

instead of embedding the chart into excel I could've just created the graph on powerpoint using python-pptx. Cant believe i overlooked it.

I followed this guide to reach my solution:
https://python-pptx.readthedocs.io/en/la...harts.html