*** UPDATE:ジャンゴ・エクセル・テンプレートはもはや維持され、代わりにまだ開発中、私はこれを入力しますがhttp://code.google.com/p/django-excel-templates/ DjangoのExcelテンプレートプロジェクトはどのようなあなたの提示を行うことを目的としてMarmir http://brianray.github.com/mm/
を試してみてください。
詳しくは、テストをご覧ください。ここでは、単純なケースである:
#
from django_excel_templates import *
from django_excel_templates.color_converter import *
from models import *
from django.http import HttpResponse
def xls_simple(request):
## Simple ##
testobj = Book.objects.all()
formatter = ExcelFormatter()
simpleStyle = ExcelStyle(vert=2,wrap=1)
formatter.addBodyStyle(simpleStyle)
formatter.setWidth('name,category,publish_date,bought_on',3000)
formatter.setWidth('price',600)
formatter.setWidth('ebook',1200)
formatter.setWidth('about',20000)
simple_report = ExcelReport()
simple_report.addSheet("TestSimple")
filter = ExcelFilter(order='name,category,publish_date,about,bought_on,price,ebook')
simple_report.addQuerySet(testobj,REPORT_HORZ,formatter, filter)
response = HttpResponse(simple_report.writeReport(),mimetype='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename=simple_test.xls'
return response
おかげで、私はそれがこのようなものであるべきと思ったが、私はどこを見れする知りませんでした。私はそれを試してみましょう –
これは素晴らしいですが、あなたが構文を理解するまではうまくいきません。トリックは、HttpResponseオブジェクトを作成し、xlwtワークブックをそのオブジェクトに保存することです。 サンプル: xls_response = HttpResponse(mimetype = "application/ms-excel") xls_response ['Content-Disposition'] = '添付ファイル。ファイル名= foo.xls ' xls。save(xls_response) 返信xls_response – ShawnMilo
ありがとう、あなたは本当に私の問題を解決しました。あなたの助けを非常に感謝します! –