Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:31:59+00:00 2026-06-06T21:31:59+00:00

Neither of these process, as would be expected reading the documentation: worksheet.close() workbook.close() Is

  • 0

Neither of these process, as would be expected reading the documentation:

worksheet.close()
workbook.close()

Is there a way to close files once done in openpyxl? Or is it handled automatically when the program quits? I dont want to leave spreadsheets left hanging in memory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:32:01+00:00Added an answer on June 6, 2026 at 9:32 pm

    well you can take a look at the source code, Im currently using 1.5.5 as such

    def load_workbook(filename, use_iterators=False):        
        if isinstance(filename, file):
            # fileobject must have been opened with 'rb' flag
            # it is required by zipfile
            if 'b' not in filename.mode:
                raise OpenModeError("File-object must be opened in binary mode")
    
        try:
            archive = ZipFile(filename, 'r', ZIP_DEFLATED)
        except (BadZipfile, RuntimeError, IOError, ValueError), e:
            raise InvalidFileException(unicode(e))
        wb = Workbook()
    
        if use_iterators:
            wb._set_optimized_read()
    
        try:
            _load_workbook(wb, archive, filename, use_iterators)
        except KeyError, e:
            raise InvalidFileException(unicode(e))
        finally:
            archive.close()
        return wb
    

    it looks like yes it does close the archive, when we load a workbook, how about when we save it?

      def save(self, filename):
        """Write data into the archive."""
        archive = ZipFile(filename, 'w', ZIP_DEFLATED)
        self.write_data(archive)
        archive.close()
    

    it looks like it also closes the archive when we save it.

    Fundamentally we read an excel workbook into memory from a file which is closed afterwards, make updates, if we don’t save it, the changes presumably are lost, if we save it, the file is closed after writing.

    Is there a way to close files once done in openpyxl? Or is it handled automatically when the program quits? I dont want to leave spreadsheets left hanging in memory.

    you can save your changes using wb.save(filename = dest_filename) as for handled automatically when readin or writing to a file then yes its closed after operation but having openpyxl automatically save your changes then no being that class Workbook(object): doesn’t have __del__ then nothing is called when that object is deleted or garbage collected, again this is for 1.5.5 the current version is 1.5.8 as of this writing, I doubt to much has changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm aware of YAML and plugins like rails-settings, but neither of these is useful
<div id=table> <input type=checkbox class=db2applforce kon value=15010 title=to be forced> Neither of these work.
It's neither 0x nor 0 ; what is it? Is there?
Are tail calls optimised in Frege. I know that there is TCO neither in
I would like to limit the amount of physical memory a process can use
I would like to know if there is a fundamental reason for limiting the
Is there a way to programmatically open and show the Windows 7 on-screen keyboard
Is there any way to execute a method of a com object inside a
I would like to know if there are any ways one can perform 'locking'
I would like to test the Flickr API using Matlab. There is no Flickr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.