0

現在、xlwt を使用してスプレッドシートを作成しており、ユーザーがダウンロードできるように、django で HttpResponse としてエクスポートしようとしています。私のコードは次のようになります。

response = HttpResponse(mimetype = "application/vnd.ms-excel")
response['Content-Disposition'] = 'attachment; filename = %s +".xls"' % u'Zinnia_Entries'
work_book.save(response)
return response

これは正しい方法のようですが、次のようになります。

Traceback (most recent call last):
  File "C:\dev\workspace-warranty\imcom\imcom\wsgiserver.py", line 1233, in communicate
    req.respond()
  File "C:\dev\workspace-warranty\imcom\imcom\wsgiserver.py", line 745, in respond
    self.server.gateway(self).respond()
  File "C:\dev\workspace-warranty\imcom\imcom\wsgiserver.py", line 1927, in respond
    response = self.req.server.wsgi_app(self.env, self.start_response)
  File "C:\dev\workspace-warranty\3rdparty\django\core\servers\basehttp.py", line 674, in __call__
    return self.application(environ, start_response)
  File "C:\dev\workspace-warranty\3rdparty\django\core\handlers\wsgi.py", line 252, in __call__
    response = middleware_method(request, response)
  File "C:\dev\workspace-warranty\imcom\imcom\seo_mod\middleware.py", line 33, in process_response
    response.content = strip_spaces_between_tags(response.content.strip())
  File "C:\dev\workspace-warranty\3rdparty\django\utils\functional.py", line 259, in wrapper
    return func(*args, **kwargs)
  File "C:\dev\workspace-warranty\3rdparty\django\utils\html.py", line 89, in strip_spaces_between_tags
    return re.sub(r'>\s+<', '><', force_unicode(value))
  File "C:\dev\workspace-warranty\3rdparty\django\utils\encoding.py", line 88, in force_unicode
    raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xd0 in position 0: invalid continuation byte. You passed in 

(この \xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00 のようなものの非常に長い行が表示されるため、残りは省略しました)

これで間違っている可能性があることについて何か考えはありますか?私の書き込み値の一部が次のようになっているためです。

work_sheet.write(r,#,information) どこで情報が unicode にキャストされていませんか?

4

2 に答える 2

0

問題を解決しました。どうやら誰かが、ハッキングをバラバラにしたり、追加したり、追加したりするようなファンキーなミドルウェアを入れたようです。など。ファイルに。すべきでないとき。

とにかく、それがなくなると、ファイルは完全にエクスポートされます。

@Storm - 助けてくれてありがとう!

于 2011-07-14T18:23:22.057 に答える
0
response['Content-Disposition'] = 'attachment; filename = %s +".xls"' % u'Zinnia_Entries'

ただあるべき

response['Content-Disposition'] = 'attachment; filename = %s.xls' % u'Zinnia_Entries'

.xls を引用符で囲まない場合、出力は次のようになります。

u'attachment; filename = Zinnia_Entries +".xls"'

だからそれを変えてみてください。

しかし、この回答もチェックしてください。xls ファイルを出力するための非常に便利な機能があります。

ジャンゴ エクセル xlwt

于 2011-07-12T22:17:22.620 に答える