我下面有创建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()
如何从客户端下载它作为报告?
答案 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',
}