Django / Python: saving HTML table in Excel

I have an HTML table that I would like to export to an Excel file. I already have the opportunity to export the table to an IQY file, but I would prefer that the user does not update the data through Excel. I just need a function that takes a snapshot of the table when the user clicks the link / button.

I would prefer this feature to be a link / button on an HTML page that allows the user to save query results displayed in a table. It would be nice if the formatting from HTML / CSS could be preserved. Is there any way to do this at all? Or something that I can change using IQY?

I can try to provide more details if necessary. Thanks in advance.

+5
source share
3 answers

You can use the excellent xlwt module. It is very easy to use and creates files in xls format (Excel 2003).

Here is an example (untested!) Of use for representing Django:

from django.http import HttpResponse
import xlwt

def excel_view(request):
  normal_style = xlwt.easyxf("""
     font:
         name Verdana
     """) 
  response = HttpResponse(mimetype='application/ms-excel')
  wb = xlwt.Workbook()
  ws0 = wb.add_sheet('Worksheet')
  ws0.write(0, 0, "something", normal_style)
  wb.save(response)
  return response
+7
source

Use CSV. There is a module in Python ("csv") for creating it, and excel can read it natively.

+2
source

Excel HTML, ( CSS).

HTML- django application/ms-excel, .

, , - Downloadify, .

0

All Articles