从Odoo应用程序下载Excel报告

时间:2019-02-17 10:35:38

标签: odoo-9

我下面有创建Excel文件的方法,但是如何像Excel报告一样将其返回?

def report_excel(self,results,report_name,header,indice,title_report):
   fileExcel = xlsxwriter.Workbook('C:\\Users\\Pc-Pc\\Desktop\\411\\'+report_name+'.xlsx')
   listUsersSheet = fileExcel.add_worksheet(report_name)
   column = 0
   row = 15
   for res in results:
       listUsersSheet.merge_range(index[ind][0] + str(row+1) + ':'+ index[ind][0] + str(row + a), res[index[ind][1]], cell_format)
   fileExcel.close()

如何从客户端下载它作为报告?

1 个答案:

答案 0 :(得分:0)

您可以为此使用Web控制器:

from openerp.http import request
from openerp import http
from openerp.addons.web.controllers.main import serialize_exception,content_disposition


class Binary(http.Controller):
    @http.route('/web/binary/download_report', type='http', auth="public")
    @serialize_exception
    def download_xls_document(self, path, filename="My report.xlsx", **kw):
        with open(path, "rb") as pdf_file:
            return request.make_response(pdf_file.read(),
                                     [('Content-Type', 'application/octet-stream'),
                                      ('Content-Disposition', content_disposition(filename))])

report_excel方法应返回:

return {
        'type': 'ir.actions.act_url',
        'url': '/web/binary/download_report?path=%s&filename=%s' % (path, "The report name.xlsx"),
        'target': 'blank',
    }