Python Forum
Is there any way to transfer charts generated from excel to powerpoint?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there any way to transfer charts generated from excel to powerpoint?
#1
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]
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to create custom charts in Python. js1152410 1 501 Nov-13-2023, 05:45 PM
Last Post: gulshan212
  HOW TO USE C# GENERATED DLL davide_vergnani 2 1,558 Jun-12-2023, 03:35 PM
Last Post: davide_vergnani
  PYQT charts in tabs frohr 10 4,227 Feb-13-2022, 04:31 PM
Last Post: Axel_Erfurt
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,835 Dec-06-2020, 04:14 PM
Last Post: Divya577
  Line charts error "'isnan' not supported for the input types," issac_n 1 2,368 Jul-22-2020, 04:34 PM
Last Post: issac_n
  Arabic language is backward in python charts bandar 3 3,528 Feb-23-2018, 07:10 AM
Last Post: Larz60+
  Best software for creating charts???? birdieman 9 6,222 Jan-13-2017, 07:20 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020