|
| Home |
|---|
In this article you will learn how to save a workbook in python using openpyxl save() function. You may use "save" or "save as" option with the same function.
If you want to save a newly created file with a new name
file = "filename.xlsx"
workbook.save(file)
There are two options save and save as for existing files. If you want to save a file with save option use the old file name in save() function. In case you want to use save as option, use a new file name and save it.
For a new excel workbook the example for saving a file is
>>> file = "newfile.xlsx"
>>> workbook.save(file)
As this is a new file and we are saving it for the first time, hence a new file name is created and provided to the save function. workbook is the workbook object we want to save.
After editing or modifying an existing file, if you want to save it with save option write
>>> workbook.save("oldfilename.xlsx")In this case simply use the old file name and the excel file will be modified, however you will not be able to access the old non-edited file.
If you want to save an existing file with a new name use save as option.
>>> file = "newfilename.xlsx"
>>> workbook.save(file)
Use this option if you want to save the data as you will be saving in a new file and the old file will still be there and accessible.
Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.
Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.
Get 1-on-1 Python tutoring designed for beginners and professionals. Learn step-by-step with real examples and personal guidance.
✓ Understand Python fundamentals quickly
✓ Solve assignments and coding problems
✓ Learn automation and real-world projects
✓ Build confidence in programming
✓ Learn from Experts & Professionals
Start learning Python today
Get expert support with your Python assignments, coursework, data analysis tasks, and real programming projects.
✓ Python project guidance
✓ Machine learning basics
✓ Data analysis with Pandas & NumPy
✓ Debugging and code improvement
✓ Interview preparation help
Finish your Python project faster
Learn Python with structured lessons, real coding practice, and personalized feedback from an experienced tutor.
✓ Live online Python tutoring via Zoom
✓ Personalized learning plan
✓ Practical coding exercises
✓ Learn Python for work or career
✓ Flexible tutoring schedule
Build real Python skills
Home Tutorial Online Live Trainings Contact Us © 2026 All rights reserved by www.PythonTutor.net