Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django中将多个文档同时导出到excel_Python_Django_Excel_Django Templates - Fatal编程技术网

Python 在Django中将多个文档同时导出到excel

Python 在Django中将多个文档同时导出到excel,python,django,excel,django-templates,Python,Django,Excel,Django Templates,我真的很难过,希望你能帮我。我有一个模板。此模板显示一张账单(西班牙语Factura),其格式可供您查看描述、托拉尔价格、公司徽标等。在此页面底部,我有一个按钮,可用于将账单的所有信息导出到excel文件中,代码如下: @login_required def descarga(request,id_factura): fact = Factura.objects.get(pk= id_factura) book = xlwt.Workbook(encoding='utf8')

我真的很难过,希望你能帮我。我有一个模板。此模板显示一张账单(西班牙语Factura),其格式可供您查看描述、托拉尔价格、公司徽标等。在此页面底部,我有一个按钮,可用于将账单的所有信息导出到excel文件中,代码如下:

@login_required
def descarga(request,id_factura):
    fact = Factura.objects.get(pk= id_factura)
    book = xlwt.Workbook(encoding='utf8')
    sheet = book.add_sheet('report')
    sheet.col(0).width = int(13*380)
    sheet.col(1).width = int(13*380)
    sheet.col(2).width = int(13*380)
    sheet.col(3).width = int(13*380)
    sheet.col(4).width = int(13*380)
    sheet.col(5).width = int(13*380)
    sheet.col(6).width = int(13*380)
    sheet.col(7).width = int(13*380)

    alignment = xlwt.Alignment()

    alignment.horz = xlwt.Alignment.HORZ_LEFT
    alignment.vert = xlwt.Alignment.VERT_TOP

    style = xlwt.XFStyle() # Create Style
    style.alignment = alignment # Add Alignment to Style

    header_font = Font()

    # Header font preferences
    header_font.name = 'Times New Roman'
    header_font.height = 20 * 15
    header_font.bold = True

    # Header Cells style definition
    header_style = XFStyle()
    header_style.font = header_font 

    font_size_style = xlwt.easyxf('font: name Times New Roman, bold on, height 280; align: wrap on, horz center')


    body_font = Font()

    # Body font preferences
    body_font.name = 'Arial'
    body_font.italic = True

    borders = Borders()
    borders.left = 1
    borders.right = 1
    borders.top = 1
    borders.bottom = 1
    header_style.borders = borders


    # body cell name style definition
    body_style = XFStyle()
    body_style.font = body_font 

    # write the header
    header = ['Cliente', 'Fecha de Factura', 'Tipo de Factura', 'Numero de Factura',    'Descripcion', 'Subtotal', 'IVA', 'Precio']
    for hcol, hcol_data in enumerate(header): # [(0,'Header 1'), (1, 'Header 2'), (2,'Header 3'), (3,'Header 4')]
    sheet.write(0, hcol, hcol_data, font_size_style)

    data = {
        "Cliente": fact.nombre_cliente,
        "Fecha de Factura":fact.fecha_factura,
        "Tipo de Factura": fact.tipo_Factura,
        "Numero de Factura": fact.numero_De_Factura,
        "Descripcion": fact.descripcion,
        "Subtotal": fact.importe_sin_iva,
        "IVA": fact.iva,
        "Precio": fact.importe_Total,
        }

    for column, key in enumerate(header, start=1):
        sheet.write(1, column, str(data[key]), body_style)


    response = HttpResponse(mimetype='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename=report.xls'
    book.save(response)
    return response 
所以,我在这里做的是将一页信息导出到excel文件

现在,用户希望在表格上选择要导出的文档,并将所有文档导出到一个excel文件中

有人知道怎么做吗!? 也许这是一个非常简单的答案,但我找不到办法

原因:所有账单都是表格中的订单,当用户单击“查看”时,会显示上面提到的页面,其中包含该账单的所有信息。因此,如果在显示表格的模板中,我没有所有票据的所有信息,即使我可以拥有所有信息,我如何选择正确的数据将其发送到excel文件,我如何在表格中选择多个并将其导出到一个excel文件


在此方面的任何帮助都将不胜感激,提前非常感谢。谢谢

你希望得到什么样的回答?你必须给用户选择多张账单的可能性。你好,丹尼尔。我不知道如何告诉函数只导出给定复选框的信息…这将是一个开始复选框的值在
请求中。GET
resp<代码>请求。发布。