Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

openpyxl save workbook to file with path

I use Openpyxl in Python to write some data in an Excel file using Workbook.
When I want to save the workbook to a file, I can only provide a filename argument, so I can not write files in other directories.

here is my sample code:

import openpyxl

file_name = "sample.xlsx"

wb = openpyxl.Workbook()

# writing some data to workbook

wb.save(filename=file_name)

I have checked the documentation via this link and found nothing more.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Python: 3.10.7

Openpyxl: 3.0.10

Can you help me provide workarounds to solve this problem?

>Solution :

Oh it’s not hard and completely as others Python methods

So just use the full file path

import openpyxl

file_path = "/your/path/here/sample.xlsx"

wb = openpyxl.Workbook()

wb.save(filename=file_path)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading