title: How can I pull information from Excel into PowerPoint using Python and keep the format?
body: <p>I've written a script with python's xlrd and pptx to read each workbook in a directory and pull information from each sheet into a table in a PowerPoint slide. It works okay if the excel table is small but I don't know what will be in these excel files. It becomes illegible when there is too many rows and columns. My main problem arose when an excel file had graphs instead of cells and the script couldn't read it. So I tried using pyscreenshot to open the document and take a screenshot but this seems slow and unnecessary. I'd like to make a slide in the PowerPoint look exactly as it would in excel but with the ability to add and change things.   </p>
  
  <pre><code>import libraries and modules
  import xlrd
  from pptx import Presentation
  from pptx.util import Inches, Pt
  import time
  import glob
  import os
  
  start = time.time()
  
  prs = Presentation()
  title_slide_layout = prs.slide_layouts[0]
  slide = prs.slides.add_slide(title_slide_layout)
  shapes = slide.shapes
  title = slide.shapes.title
  subtitle = slide.placeholders[1]
  
  title.text = "Dashboard Generator"
  subtitle.text = "made with Python-pptx and xlrd"
  
  for filename in glob.glob(os.path.join("C:/Users/penelope/Desktop/PMO/myfiles/", '*.xlsx')):
      print(filename)
      file_location = filename
      try: 
          workbook = xlrd.open_workbook(file_location)
          nsheets = workbook.nsheets
          for n in range(0, nsheets):
              sheet = workbook.sheet_by_index(n)
              print("sheet:", sheet)
              rows = sheet.nrows
              cols = sheet.ncols
              c = cols
              r = rows
              if c &gt; 0:
                  print(c, r)
                  slide = prs.slides.add_slide(prs.slide_layouts[5])
                  shapes = slide.shapes
                  title = slide.shapes.title
                  title.text = "Table testing"
                  left = Inches(0.0)
                  top = Inches(2.0)
                  width = Inches(6.0)
                  height = Inches(4.0)
                  num = 10.0/c
                  table = shapes.add_table(rows, cols, left, top, width, height).table
                  for i in range(0, c):
                      table.columns[i].width = Inches(num)
                  for i in range(0,r):
                      for e in range(0,c):
                          table.cell(i,e).text = str(sheet.cell_value(i,e))
                          cell = table.rows[i].cells[e]
                          paragraph = cell.text_frame.paragraphs[0]
                          paragraph.font.size = Pt(11)
      except:
          print("Error!")
          pass
  
  prs.save('powerpointfile1.pptx')
  end = time.time()
  print(end - start)
  </code></pre>
  
  <p>And this is my screenshot script:</p>
  
  <pre><code>import os
  import time
  import pyscreenshot as ImageGrab
  from PIL import Image
  
  if __name__ == "__main__":
      os.system('start excel.exe "C:/Users/penelope/Desktop/PMO/TestCase.xlsx"')
      time.sleep(3)
      im=ImageGrab.grab(bbox=(24,210,1800,990))
      im.save("image7.png")
      img = Image.open('image7.png')
      img.show()
  </code></pre>