New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add support for Google App Engine #28

Closed
jmcnamara opened this Issue Jun 27, 2013 · 5 comments

Comments

3 participants
@jmcnamara
Owner

jmcnamara commented Jun 27, 2013

XlsxWriter doesn't currently work with Google App Engine because it uses a temporary directory to assemble the XLSX sub-component files prior to creating an output file.

@zgott

This comment has been minimized.

Show comment
Hide comment
@zgott

zgott Jun 27, 2013

Comment so I get notifications. Eagerly awaiting.

Thanks!

zgott commented Jun 27, 2013

Comment so I get notifications. Eagerly awaiting.

Thanks!

@ameikle

This comment has been minimized.

Show comment
Hide comment
@ameikle

ameikle Oct 5, 2013

How to implement XlsxWriter in GAE

ameikle commented Oct 5, 2013

How to implement XlsxWriter in GAE

jmcnamara added a commit that referenced this issue Nov 12, 2013

Initial in-memory file handling.
Initial handling of all files in memory so the xlsxwriter
can be used with the Google App Engine. Issue #28.
@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 12, 2013

Owner

I've pushed an in-memory implementation of XlsxWriter that should work with the GAE.

Can you try it out and let me know if you have any issues. It is on the gae branch.

This is a first pass so expect some minor issues. I'll be refactoring/reworking in the next few days.

To get the in-memory behaviour (i.e., no temp file) you need to pass 'in_memory': True as a constructor option, see below:

import SimpleHTTPServer
import SocketServer
import StringIO

import xlsxwriter


class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):

    def do_GET(self):
        # Create a new workbook in memory and add a worksheet
        output = StringIO.StringIO()

        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        worksheet = workbook.add_worksheet()

        # Write some test data.
        worksheet.write(0, 0, 'Hello, world!')

        # Close the workbook before streaming the data.
        workbook.close()

        # Rewind the buffer.
        output.seek(0)

        # Construct a server response.
        self.send_response(200)
        self.send_header('Content-Disposition', 'attachment; filename=test.xlsx')
        self.send_header('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
        self.end_headers()
        self.wfile.write(output.read())
        return


print("Server listening on port 8000...")
httpd = SocketServer.TCPServer(("", 8000), Handler)
httpd.serve_forever()
Owner

jmcnamara commented Nov 12, 2013

I've pushed an in-memory implementation of XlsxWriter that should work with the GAE.

Can you try it out and let me know if you have any issues. It is on the gae branch.

This is a first pass so expect some minor issues. I'll be refactoring/reworking in the next few days.

To get the in-memory behaviour (i.e., no temp file) you need to pass 'in_memory': True as a constructor option, see below:

import SimpleHTTPServer
import SocketServer
import StringIO

import xlsxwriter


class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):

    def do_GET(self):
        # Create a new workbook in memory and add a worksheet
        output = StringIO.StringIO()

        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        worksheet = workbook.add_worksheet()

        # Write some test data.
        worksheet.write(0, 0, 'Hello, world!')

        # Close the workbook before streaming the data.
        workbook.close()

        # Rewind the buffer.
        output.seek(0)

        # Construct a server response.
        self.send_response(200)
        self.send_header('Content-Disposition', 'attachment; filename=test.xlsx')
        self.send_header('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
        self.end_headers()
        self.wfile.write(output.read())
        return


print("Server listening on port 8000...")
httpd = SocketServer.TCPServer(("", 8000), Handler)
httpd.serve_forever()

jmcnamara added a commit that referenced this issue Nov 12, 2013

Initial in-memory file handling.
Initial handling of all files in memory so the xlsxwriter
can be used with the Google App Engine. Issue #28.

jmcnamara added a commit that referenced this issue Nov 12, 2013

Initial in-memory file handling.
Initial handling of all files in memory so the xlsxwriter
can be used with the Google App Engine. Issue #28.

jmcnamara added a commit that referenced this issue Nov 12, 2013

In-memory file handling.
Implemented handling of all files in memory so the xlsxwriter
can be used with the Google App Engine. Issue #28.
@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 12, 2013

Owner

Merged to master.

Owner

jmcnamara commented Nov 12, 2013

Merged to master.

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 13, 2013

Owner

These changes are now available in XlsxWriter version 0.4.8 on PyPi.

See the updated Httpd example.

If there are any problems open a new issue.

Enjoy.

Owner

jmcnamara commented Nov 13, 2013

These changes are now available in XlsxWriter version 0.4.8 on PyPi.

See the updated Httpd example.

If there are any problems open a new issue.

Enjoy.

@jmcnamara jmcnamara closed this Nov 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment