您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

django excel xlwt

django excel xlwt

整齐的包装!我不知道这个

根据文档,该save(filename_or_stream)方法采用要保存的文件名或要写入的类似文件的流。

而Django响应对象恰好是一个类似文件的流!所以做吧xls.save(response)。查看有关使用ReportLab 生成PDF的Django文档,以了解类似情况。

编辑:(改编自肖恩·米洛的评论):

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

然后,从你的视图函数中,只需创建xls对象并完成

return xls_to_response(xls,'foo.xls')
Go 2022/1/1 18:18:42 有557人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶