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

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

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()

Leave a Reply