Streamed read only Excel File

Issue #1141 resolved
Rob Harriman created an issue

Version 2.6 has a breaking change in our Pyramid web application.

This issue is related to the change in how workbooks are read. Both 2.5 and 2.6 validate the input and create an archive. If a load_workbook is called as read_only, 2.6 creates a new archive from the validated archive filename (line 194 2.5 creates a second archive too, but from the original input filename (line 205

Both work fine when the file is on disk, but the second archive in 2.6 cannot be created ('int' object has no attribute 'seek') from a streamed file upload.

I'm struggling with finding the exact cause, so thought to try posting here. The first archive is created on Line 122 of 2.6, and works properly. Filename is a BufferedReader type at this point. When the second archive is created, the argument (self.archive.filename) is an int.

If read-only is not set, loading the streamed workbook works as expected (the second archive is not created).

Comments (4)

  1. CharlieC

    Thanks for giving 2.6 a test and the report. I suspect it was PR #294 that broke this. We were doing some cleanup of this very old code at our recent sprint and the change broke no tests…

    You should be able to reconstruct the relevant behaviour from this and thus provide a relevant test and PR.

    cc @kbr 'cos he broke it! ;-)

  2. CharlieC

    So, I think I have an example that works with 2.5 but not with 2.6

    from openpyxl import Workbook, load_workbook
    from io import BytesIO
    buffer = BytesIO()
    wb = Workbook()
    wb1 = load_workbook(buffer)
    wb2 = load_workbook(buffer, read_only=True)
  3. Log in to comment