@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文件中...
有没有人知道如何做到这一点!? 也许是一个非常简单的答案,但我找不到办法。
原因:所有账单都是在表格中排序,当用户点击“查看”时,它会显示上面提到的页面以及该账单的所有信息。那么,如果在显示表格的模板中我没有所有账单的所有信息,即使我可以拥有所有信息,我怎么能选择多个IN THE TABLE并将它们全部输出到一个excel文件中,如何选择正确的数据将其发送到Excel文件?
对此的任何帮助都将非常感谢,非常感谢您提前。感谢