I need to move multiple Excel tables into multiple powerpoints as high-resolution EMF images. I cannot link the data into powerpoint as I need to update 400+ different powerpoints from 400+ different Excel models that originate from a single Excel template and VBA is not an option. All the powerpoints and Excel models are formatted and laid out exactly the same. The code below works but the resolution of the image pasted into PowerPoint is too low and I cannot figure out how to increase it.
import win32com.client as win32
from pptx import Presentation
from PIL import ImageGrab, Image
import os
modelPath = "P:/Folder"
FileName = "XXXX.xlsx"
outT = "P:/Folder/Charts"
cellRange = 'A1:C10'
sheetName = 'Norm'
o = win32com.client.Dispatch('Excel.Application')
wb = o.Workbooks.Open(modelPath +"/"+FileName)
wsT = wb.Worksheets['Norm']
# Grab Table
wsT.Range(wsT.Cells(4,3),wsT.Cells(41,8)).CopyPicture(Format = 2)
imgEMF = ImageGrab.grabclipboard()
imgFile = os.path.join(outT,'norm.emf')
imgEMF.save(imgFile, 'PNG', compress_level=0, dpi=(5000, 5000))
t=ImageGrab.grabclipboard()
# remove old tables
pres = Presentation("Test.pptx") # name of existing pptx
t = [26, 28, 31, 33, 34]
for i in t:
slides = pres.slides[i]
shapes = slides.shapes
for shape in shapes:
if shape.shape_type == 13 or shape.shape_type == 1:
shapes.element.remove(shape.element)
#add new tables
slide = pres.slides[31]
slide.shapes.add_picture(out+'/norm.emf', left = Inches(0.41), top = Inches(2.25), width = Inches(6.17), height = Inches(3.0))
# I cut all but one table from the code
pres.save('Test6.pptx')
5