Skip to content

Instantly share code, notes, and snippets.

@einsty
Last active April 22, 2016 12:16
Show Gist options
  • Save einsty/2189cae4175f619cff0f to your computer and use it in GitHub Desktop.
Save einsty/2189cae4175f619cff0f to your computer and use it in GitHub Desktop.
Loop over Directory of Excel Files and convert each one to PDF

#Convert Excel files to PDF

There are tons of solutions out there that will "automate" the conversion of Microsoft Office files to PDF. Unfortunately, many of them are bloated with spammy advertisements or will watermark your documents or any number of other unfriendly results.

If all that you really need to do is simply loop over a directory of say 30 or 300 or 3,000 Microsoft Office files and convert them each 1 by 1 into PDF's then a very lightweight solution can be found here.

Thanks to a conversation on Stack Overflow I came across the Apached Licensed OfficeToPDF.exe package, and with that and bit of ol' school Batch scripting, this task can be done for free, without spammy bloatware and also very quickly on your local machine.

Setup

First, download the OfficeToPDF.exe file and put that exe file into the directory that holds all of your Office documents.

Next, use whatever method you prefer to get a Windows Command open at that directory. I prefer to use the Windows Explorer and then hold the Shift key while doing a Right Click on the containing folder. This will give me the option to "Open Command Window here".

Run the task

Once you are in the directory with the .exe file and all of the Excel documents, you can simply type in the following DOS command to loop over the files and convert them to PDF.

Example 1.

Convert all Excel files in the current directory and have the PDF file named the same as the original file, but with a .pdf extension.

for %i in (*.xls) do OfficeToPDF.exe "%i"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment