question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with file sometimes unable to be opened by Numbers

See original GitHub issue

Hi,

I am using XlsxWriter to do export from Django through an HttpResponse and sometimes the file can’t be opened by Numbers, but can always be opened by LibreOffice.

I am using Python version 2.7.12 and XlsxWriter 1.0.2 and Numbers version 4.3.1 5249 and LibreOffice version 5.3.4.2.

Here is basically how the response is coded, mashed into one script obviously:


from django.http import HttpResponse
from django.views.generic.base import TemplateView
import xlsxwriter

class XlsxResponse(HttpResponse):
    def __init__(self, writer_klass, *args, **kwargs):
        kwargs["content_type"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        super(XlsxResponse, self).__init__(*args, **kwargs)
        self._writer_klass = writer_klass
        self["Content-Disposition"] = "attachment; filename=\"export.xlsx\""

    def process(self, content):
        self._writer_klass(self).handle(content)


class XlsxWriter(object):
    def __init__(self, response):
        self._response = response
        self.wb = xlsxwriter.Workbook(response, {"in_memory": True})

    # This is implemented by the sub-classes, which handle worksheets
    # and formats and stuff.
    def _handle(self, content):
        raise NotImplementedError

    def handle(self, content):
        try:
            self._handle(content)
        finally:
            self.wb.close()


class CalendarExportView(TemplateView):
    def render_to_response(self, context, **response_kwargs):
        response = nexus_http.XlsxResponse(writer_klass=CalendarWriter)
        response.process(context)
        return response

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jmcnamaracommented, Feb 9, 2018

Closing.

0reactions
jmcnamaracommented, Feb 13, 2018

Thanks for the update. Hopefully it will help someone else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1) 'The document “*.numbers” could not b… - Apple Community
1) 'The document “*.numbers” could not be opened. ' and 2) '"untitled" can't be opened right now. Numbers couldn't read the file'.
Read more >
How to recover when Apple Numbers says a file “can't be ...
I named the files created that way with an “09” suffix, and suddenly they opened on the iPad – with all the tables...
Read more >
6 Best Ways to Fix Numbers App Not Opening on Mac
6 Best Ways to Fix Numbers App Not Opening on Mac · 1. Force Quit and Relaunch Numbers App · 2. Update the...
Read more >
How to Fix "Numbers File Can't Be Opened on macOS 10.14"
The first thing to do is to reboot the device in Safe Mode in order to determine whether there is a newly installed...
Read more >
Why Your PC Won't Open NUMBERS Files - File Magic
This error is quite easy to solve. Simply right-click on the NUMBERS file and select Numbers Spreadsheet from the dropdown list to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found