write_only worksheet does not save freeze_panes

Issue #615 resolved
Daniel Lenski created an issue

With openpyxl 2.3.4, the following simple test case shows that freeze_panes are not saved for WriteOnlyWorksheets:

#!/usr/bin/env python2

import openpyxl

for write_only in (True, False):
    wb = openpyxl.Workbook(write_only=write_only)
    ws = wb.create_sheet() if write_only else wb.active

    ws.append(['foo','bar','baz'])
    ws.append([1,2,3])
    ws.freeze_panes = "A2"
    ws.auto_filter.ref="A1:C1" # auto_filter property does work
    wb.save('/tmp/test_write_only_%s.xlsx' % write_only)

It appears that the WriteOnlyWorksheet class contains the logic to write the auto_filter, but not to write the freeze_panes view.
(https://bitbucket.org/openpyxl/openpyxl/src/e0820e3fa62ccde44733e058770477b0b3a897e7/openpyxl/writer/write_only.py?at=2.3.4&fileviewer=file-view-default#write_only.py-124:126)

Comments (4)

  1. CharlieC

    Actually, the problem here is subtle: everything that appears in the file before the actual cell data must be created before cells are added because it must written to the file before then. Anything that comes after the cells can be added or altered at any time.

    import openpyxl
    
    for write_only in (True, False):
        wb = openpyxl.Workbook(write_only=write_only)
        ws = wb.create_sheet() if write_only else wb.active
        ws.freeze_panes = "A2"
    
        ws.append(['foo','bar','baz'])
        ws.append([1,2,3])
        ws.auto_filter.ref="A1:C1" # auto_filter property does work
        wb.save('/tmp/test_write_only_%s.xlsx' % write_only)
    

    Does what you expect. The docs could probably be improved here. Maybe we could add guards to relevant attributes which would inform the user otherwise you have to know the file format by heart.

  2. Log in to comment