用Spyn发送XLS

2024-04-19 20:45:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有个问题。。你知道吗

我想通过spyne的webservices发送XLS,但是我需要,如果这个URL

http://127.0.0.1:5000/download/file?A=1

将被按下,整个XLS将下载。这可能吗?你知道吗

这是我的密码:

class xlsDownload(spyne.Service):
    __service_url_path__ = '/download';
    __in_protocol__ = HttpRpc(validator='soft');
    __out_protocol__ = MessagePackDocument()#HtmlRowTable()#MessagePackRpc()

    @spyne.srpc(Unicode, _returns=File)
    def Function(A):
        GetXLS(A)
        return File.Value(data=open("File.xls", 'rb', type='application/vnd.ms-excel');

有人能告诉我,如果我能用Spyne下载整个XLS(我可以在URL被点击后对该文件做任何事情)吗?你知道吗

非常感谢, 祝你今天愉快


Tags: webhttpurl密码downloadservicexlsprotocol
1条回答
网友
1楼 · 发布于 2024-04-19 20:45:54

这是烧瓶里的

@app.route("/download/file")
def xlsDownload(A):
    GetXLS(A)
    response = Response(bytearray(open("file.xls", "rb").read()))
    response.headers["Content-Type"] = "application/vnd.ms-excel"
    response.headers["Content-Disposition"] = "attachment; filename = file.xls"
    return response

你会问:

http://127.0.0.1:5000/download/file?A=1

我希望这有时能帮助别人。。:)

相关问题 更多 >