python - Modify the width of a cell with Xlwt in Django -
This is the code that I have in my view.py to download notification of a template in a special file: < / p>
def descarga (request, id_factura): really = Factura.objects.get (p = id_factura) book = xlwt.Workbook (= 'UTF8' encoding) sheet = book.add_sheet ( 'report' ) align = xlwt.Alignment () alignment.horz = xlwt.Alignment.HORZ_LEFT alignment.vert = xlwt.Alignment.VERT_TOP style = xlwt.XFStyle () # Create style style.alignment = alignment # style Add alignment header_font = font () # Header Font Preferences header_font.name = 'Ti mes New Roman 'header_font.height = 20 * 15 header_font.bold = true # header cell style definition header_style = XFStyle () header_style.font = header_font body_font = Font () # body font preferences Body_font.name =' Arial 'body_font.italic = True border = borders () borders. Left = 1 bore ders.right = 1 borders.top = 1 borders.bottom = 1 header_style.borders = borders # body cell named style definition body_style = XFStyle () body_style.font = body_font # header header type = [ 'Cliente', 'Fecha de Factura' Tipo D Factura ',' Número de Factura ',' Description ',' subtotal ',' IVA '' Hcol, of] the hcol_data calculation (header): # [( 0, 'Precio Header 1'), (1, 'Header 2'), (2, 'Header 3'), (3, 'Header 4')] sheet. Written (0, HOCL, HCL_Data, Header_style) # Write data, you can also get it from your model data = {"Cliente": f act.nombre_cliente, "Fecha de Factura" Factkfecha_factura, "Tipo de Factura": fact.tipo_Factura, "Número de Factura" Factknumero_De_Factura, "description": the fact .descripcion, "subtotal": fact.importe_sin_iva, "IVA": for fact.iva, "Precio": column.file.importe_Total}}, calculation key (header, start = 1): sheet.write (1, column, straw (data [key]), body_style) Feedback = HTPRPS response (mime type = 'app / window.x-excel') feedback ['content-dispute'] = 'attachment; Filename = report.xls' book.save (feedback) Return response
What I'm trying to do, to fit the information to increase the width of the column, without any success
Any help would really be appreciated. Thanks
What is the content of header_style? Try to use
... content_format = 'align: wrap on' sheet.write (0, hcol, hcol_data, ezxf (content_format)) ...
and you can define the width of your cell at the beginning:
... sheet.col (0) .width = int (13 * 260) # 0 Meaning Colonel 0, 260 stands for 1 mm so that the width of the column is 13mm. ...
Hope it helps.
Comments
Post a Comment