I have some code that opens an Excel workbook with xlrd
, copies it with xlutils
, updates it with xlwt
and then writes it back out to another file.
The resulting workbook is missing all the named ranges that were present in the original. I'm 100% sure the named ranges are present in the original because I'm actually reading them (from the xlrd
object, before the copy) and basing my updates on them.
Assuming that this is the natural effect of using xlutils.copy.copy
, does xlwt
have some way for me to recreate the named ranges that I read from the xlrd
version of the same workbook? The documentation (at least, what I could find) is sparse.
Here is a python session that shows the problem:
>>> from xlrd import open_workbook
>>> wb = open_workbook('sc_auction_template.xls', formatting_info=True)
>>> print len(wb.name_obj_list) # see, there are named ranges
9
>>> from xlutils.copy import copy
>>> wb2 = copy(wb)
>>> wb2.save('test.xls')
>>> wb = open_workbook('test.xls')
>>> print len(wb.name_obj_list) # but now there are none!
0