2

I have an excel table that I am building using python logic via xlwings. Once calculated, I would like to copy that table (ie its range) and save it as an image (similar format to select range -> copy -> right click -> paste as image ). End goal is to use pptx to include the table in a powerpoint presentation

Is this possible?

Merv Merzoug
  • 1,149
  • 2
  • 19
  • 33

2 Answers2

0

I found that the best solution for this is to embed the excel range into the powerpoint presentation.

Copy your excel range, go to the ribbon and click on the triangle under 'Paste', 'Paste Special', 'Paste Link'

This will automatically reflect the changes in the presentation

Merv Merzoug
  • 1,149
  • 2
  • 19
  • 33
0

The way to do this is a bit hacky and there must be a cleaner way but this is what I have found that works for me. The answer below assumes you have data in cells A1 through B3 but you could adjust it for whatever your specific range is.

import xlwings as xw
sht.range('A1:B3').api.CopyPicture(Appearance=2) #2 copies as when it is printed
sht.api.Paste()
pic=sht.pictures[0]
pic.api.Copy()

from PIL import ImageGrab
img = ImageGrab.grabclipboard()
img.save('test.png') #You can obviously save this as whatever filename you want