Получить строку таблицы, подчеркнутую с помощью python_docx - PullRequest
0 голосов
/ 01 марта 2019

Я хочу получить строку таблицы, подчеркнутую python-docx , поэтому я следовал этому ответу , но я получил каждое слово в строке, подчеркнутое отдельно:

enter image description here

Я хочу подчеркнуть всю строку следующим образом:

enter image description here

Это связанный код:

    document = Document()

    section = document.sections[-1]
    section.left_margin = Inches(0.5)
    section.right_margin = Inches(0.5)

    style = document.styles['Normal']
    font = style.font
    font.name ='Arial'
    font.size = Pt(10)

    document.add_heading("COMPANY")
    document.add_paragraph("Operación de {} del día {}".format(operation_type[context['operation_type_id']], context['operation_date']))
    document.add_paragraph(weekdays[str(self.get_operation_date().weekday())])

    transfers = context['transfers']

    table = document.add_table(rows=len(transfers), cols=10)
    hdr_cells = table.rows[0].cells
    run = []
    run.append(hdr_cells[0].paragraphs[0].add_run('Booking'))
    run[0].underline = True
    run[0].font.size = Pt(8)
    run.append(hdr_cells[1].paragraphs[0].add_run('Nombre'))
    run[1].underline = True
    run[1].font.size = Pt(8)
    run.append(hdr_cells[2].paragraphs[0].add_run('#'))
    run[2].underline = True
    run[2].font.size = Pt(8)
    run.append(hdr_cells[3].paragraphs[0].add_run('Vuelo'))
    run[3].underline = True
    run[3].font.size = Pt(8)
    run.append(hdr_cells[4].paragraphs[0].add_run('Hr'))
    run[4].underline = True
    run[4].font.size = Pt(8)
    run.append(hdr_cells[5].paragraphs[0].add_run('P Up'))
    run[5].underline = True
    run[5].font.size = Pt(8)
    run.append(hdr_cells[6].paragraphs[0].add_run('Traslado'))
    run[6].underline = True
    run[6].font.size = Pt(8)
    run.append(hdr_cells[7].paragraphs[0].add_run('Circuito'))
    run[7].underline = True
    run[7].font.size = Pt(8)
    run.append(hdr_cells[8].paragraphs[0].add_run('Priv?'))
    run[8].underline = True
    run[8].font.size = Pt(8)
    run.append(hdr_cells[9].paragraphs[0].add_run('Agencia'))
    run[9].underline = True
    run[9].font.size = Pt(8)


    current_directory = settings.MEDIA_DIR
    file_name = "Operaciones {} {}.docx".format(operation_type[context['operation_type_id']], context['operation_date'])
    document.save("{}/{}".format(current_directory, file_name))

Есть ли способ, которым я могу добиться этого с помощью python-docx ?

...