title: How do I batch convert .xlsx to PDF from folder using Python?
body: <p>I have a pretty mundane task quarterly where I need to convert 40 files to PDF from XLSX. I have some code that can print one file as a pdf but not multiple pages and it cannot print multiple files. I want to access the folder, open the .xlsx and the print them to a pdf.</p>
  <p>To take it a step further and my code does not, I want to only print two sheets named: &quot;Page 1&quot; and &quot;Page 2&quot;</p>
  <p>I have tried one file and that works with a slightly modified code.</p>
  <pre><code>import os
  from win32com import client
  xlApp = client.Dispatch(&quot;Excel.Application&quot;)
  
  source = r&quot;C:\Users\user1\.spyder-py3\QAR&quot;
  output = r&quot;C:\Users\user1\.spyder-py3\QAR&quot;
  
  dir_list = os.listdir(source)
  os.chdir(source)
  
  for i in range(len(dir_list)):
      filename = dir_list[i]
      print(filename)
      books = xlApp.Workbooks.Open(filename)
  
      
      for file in range(len(filename)):
            ws = books.Worksheets[1]
            ws.Visible = 1
            ws.ExportAsFixedFormat(0, filename + '\.pdf')
  </code></pre>
  <p>I would ideally like to see the files saved as individual pdfs with two sheets, Page 1 and Page 2.</p>
  <p>I can get the Excel files open or save one excel as a pdf with one page but can't seem to put it together.</p>