---
title: Save an Excel sheet as pdf with Python and win32
description: Saving a finished report or table in Excel is easy. You save the sheet as Pdf. Doing this automatically with Python is trickier, though.
---

[Skip to content](https://www.connysoderholm.com/blog/save-an-excel-sheet-as-pdf-with-python-and-win32#main-content)

![Conny-Söderholm](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg)

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

Open main navigation

Close main navigation

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

 December 15, 2019

# Save an Excel sheet as pdf with Python and win32

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm)

Share: [facebook-f icon](http://www.facebook.com/share.php?u=https://www.connysoderholm.com/blog/save-an-excel-sheet-as-pdf-with-python-and-win32) [linkedin-in icon](http://www.linkedin.com/shareArticle?mini=true&url=https://www.connysoderholm.com/blog/save-an-excel-sheet-as-pdf-with-python-and-win32) [Twitter icon](https://twitter.com/intent/tweet?url=https://www.connysoderholm.com/blog/save-an-excel-sheet-as-pdf-with-python-and-win32) [pinterest-p icon](http://pinterest.com/pin/create/link/?url=https://www.connysoderholm.com/blog/save-an-excel-sheet-as-pdf-with-python-and-win32) [envelope icon](mailto:?body=https://www.connysoderholm.com/blog/save-an-excel-sheet-as-pdf-with-python-and-win32)

Saving a finished report or table in Excel is easy. You choose "SaveAs" and save the sheet as Pdf. Doing this automatically with Python is trickier, though. In this post, we will inspect on how to do this with the win32 library. The full code is available at the bottom of the post. Note that you need Excel installed in order to run this script successfully.

Source code is available on [GitHub](https://github.com/consod/articles/blob/main/Pywin32/save_excel_as_pdf.py).

 ![Woman working with spreadsheets on her computer](https://www.connysoderholm.com/hs-fs/hubfs/image-png-Aug-09-2023-02-56-18-4427-AM.png?width=767&height=511&name=image-png-Aug-09-2023-02-56-18-4427-AM.png)

## Installing dependencies

Install the win32 library first with: `pip install pypiwin32`.

This will install the Win32 Api library, which according to [PyPi](https://pypi.org/project/pypiwin32/219/)contains:

*Python extensions for Microsoft Windows Provides access to much of the Win32 API, the ability to create and use COM objects, and the Pythonwin environment.*

## File paths

To get the file paths we use pathlib. Pathlib was introduced in Python 3.4 so it is quite new (Using Python 3.8 during the writing of this article). We specify the name of the Excel workbook we want to make a pdf of, and also the output pdf's name.

`excel_file = "pdf_me.xlsx"`  
`pdf_file = "pdf_me.pdf"`

We then create paths from our current working directory (cwd) with Pathlibs cwd() method.

`excel_path = str(pathlib.Path.cwd() / excel_file)`  
`pdf_path = str(pathlib.Path.cwd() / pdf_file)`

## Firing up Excel

Excel is next up. We start the Excel application and hide it.

`excel = client.DispatchEx("Excel.Application")`  
`excel.Visible = 0`

We then open our workbook  `wb = excel.Workbooks.Open(excel_path)` and load our first sheet with `ws = wb.Worksheets[1]`

Now it is time to use the SaveAs to save our sheet as a pdf. `wb.SaveAs(pdf_path, FileFormat=57)`Fileformat 57 is the pdf file format.

We then close our workbook and quit our Excel application. Our pdf is now saved in our working directory.

## The code

```
from win32com import client

import win32api

import pathlib
### pip install pypiwin32 if module not found

excel_file = "pdf_me.xlsx"

pdf_file = "pdf_me.pdf"

excel_path = str(pathlib.Path.cwd() / excel_file)

pdf_path = str(pathlib.Path.cwd() / pdf_file)

excel = client.DispatchEx("Excel.Application")

excel.Visible = 0

wb = excel.Workbooks.Open(excel_path)

ws = wb.Worksheets[1]

try:

    wb.SaveAs(pdf_path, FileFormat=57)

except Exception as e:

    print("Failed to convert")

    print(str(e))

finally:

    wb.Close()

    excel.Quit()
```

 

[Python](https://www.connysoderholm.com/blog/tag/python), [Excel](https://www.connysoderholm.com/blog/tag/excel)

## Related posts

[Python](https://www.connysoderholm.com/blog/tag/python), [pypdf2](https://www.connysoderholm.com/blog/tag/pypdf2)

## [Splitting a pdf to single pages with PyPDF2](https://www.connysoderholm.com/blog/splitting-a-pdf-to-single-pages-with-pypdf2)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 December 13, 2019

Splitting Pdfs with Python In this post, we are going to have a look at how to split all pages from...

[Read more](https://www.connysoderholm.com/blog/splitting-a-pdf-to-single-pages-with-pypdf2)

[Python](https://www.connysoderholm.com/blog/tag/python), [openpyxl](https://www.connysoderholm.com/blog/tag/openpyxl), [Excel](https://www.connysoderholm.com/blog/tag/excel)

## [The elegance of Python: Interacting with Excel](https://www.connysoderholm.com/blog/the-elegance-of-python-interacting-with-excel)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 June 2, 2018

[Read more](https://www.connysoderholm.com/blog/the-elegance-of-python-interacting-with-excel)

[Python](https://www.connysoderholm.com/blog/tag/python), [pypdf2](https://www.connysoderholm.com/blog/tag/pypdf2)

## [Rotate PDF files with PyPdf2 and Tkinter!](https://www.connysoderholm.com/blog/rotate-pdf-files-with-pypdf2-and-tkinter)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 January 24, 2020

Rotating PDF files with PyPDF2 and Tkinter Introduction Sometimes we need simple tools to get the...

[Read more](https://www.connysoderholm.com/blog/rotate-pdf-files-with-pypdf2-and-tkinter)

[linkedin-in icon](https://www.linkedin.com/in/connysoderholm) [Follow us on Facebook](https://www.youtube.com/@connysoderholm1473)

- [Home](https://www.connysoderholm.com)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)
- [Privacy Policy](https://www.connysoderholm.com/privacy-policy)
- [Disclaimer](https://www.connysoderholm.com/disclaimer)

---

[![Conny Söderholm Logo](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg "Conny Söderholm Logo")](http://Conny%20Söderholm)

Copyright © 2026 Conny Söderholm

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Conny Söderholm",
    "url" : "https://www.connysoderholm.com/blog/author/conny-soderholm"
  },
  "dateModified" : "2023-08-09T03:01:28.362Z",
  "datePublished" : "2019-12-15T21:48:38.000Z",
  "headline" : "Save an Excel sheet as pdf with Python and win32",
  "mainEntityOfPage" : {
    "@id" : "https://www.connysoderholm.com/blog/save-an-excel-sheet-as-pdf-with-python-and-win32",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg"
    },
    "name" : "Conny Söderholm"
  }
}
```