Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 206413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:38:38+00:00 2026-05-11T17:38:38+00:00

On a django site, I want to generate an excel file based on some

  • 0

On a django site, I want to generate an excel file based on some data in the database.

I’m thinking of using xlwt, but it only has a method to save the data to a file. How can get the file to the HttpResponse object? Or maybe do you know a better library?

I’ve also found this snippet but it doesn’t do what I need. All I want is a way to get the stream from the xlwt object to the response object (without writing to a temporary file)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:38:38+00:00Added an answer on May 11, 2026 at 5:38 pm

    neat package! i didn’t know about this

    According to the doc, the save(filename_or_stream) method takes either a filename to save on, or a file-like stream to write on.

    And a Django response object happens to be a file-like stream! so just do xls.save(response). Look the Django docs about generating PDFs with ReportLab to see a similar situation.

    edit: (adapted from ShawnMilo’s comment):

    def xls_to_response(xls, fname):
        response = HttpResponse(mimetype="application/ms-excel")
        response['Content-Disposition'] = 'attachment; filename=%s' % fname
        xls.save(response)
        return response
    

    then, from your view function, just create the xls object and finish with

    return xls_to_response(xls,'foo.xls')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a Django site, but I've drank the Koolaid and I want to
Our Django site is built using Mako templates. We want to use a third
i want to deploy my django site to apache , but i cant find
I'm using django-haystack for a search page on my site, and I want to
I'm building a Django site and trying to use the request.is_ajax() function... But it's
I have a nice and lovely Django site up and running, but have noticed
I'm working on what I think is a pretty standard django site, but am
I'm rewriting a PHP+MySQL site that averages 40-50 hits a day using Django. Is
I want to add a 404 page on my Django site. I've created a
I am creating a django-based site that will serve flash apps that occasionally access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.