23

I am using the function open_workbook() to open an excel file. But I cannot find any function to close the file later in the xlrd module. Is there a way to close the xls file using xlrd? Or is not required at all?

GreenMatt
  • 18,244
  • 7
  • 53
  • 79
Sumod
  • 3,806
  • 9
  • 50
  • 69

2 Answers2

22

Digging into the mailing list archive, it seems that the file object is closed directly by the constructor, so you don't need to close it explicitly.

Andrea Spadaccini
  • 12,378
  • 5
  • 40
  • 54
  • 6
    Note if you use on_demand=True the file is _not_ closed, even if the workbook is collected. This is documented in the xlrd comments. You should be careful to call release_resources() before letting the workbook go away. – Paul Du Bois Nov 23 '11 at 03:50
6

The open_workbook calls the release_resources ( which closes the mmaped file ) before returning.

Tripy
  • 96
  • 2