Closed bwsoftw closed 1 year ago
Have a look at this StackOverflow answer: https://stackoverflow.com/a/68507579/1902513
Basically, only a run can be made bold or not. A run is a sequence of characters that share the same character formatting. So if the word you want to bold is not in a run by itself, you need to make it so and then apply bold to that run. That's what the linked code does.
I'm having trouble taking existing words in the document and modifying them with the library. The times I managed to leave it in bold, it was in the paragraph where it contained the words that I wanted to leave in bold, instead of leaving just the word. Here is my code:
`` import os import shutil from docx import Document import requests from senhaapi import API_KEY import json from docxtpl import DocxTemplate import docx from docx.shared import Pt import re from docx.oxml.ns import qn from docx.oxml import OxmlElement from docx.enum.text import WD_PARAGRAPH_ALIGNMENT from docx.shared import RGBColor
ans = read_multiple_choice( "Escolha a matéria da prova que será submetida", [{"label": "Português", "value": "portugues"}, {"label": "Matemática", "value": "matematica"}, {"label": "Geografia", "value": "geografia"}, {"label": "História", "value": "historia"}, {"label": "Física", "value": "fisica"}, {"label": "Química", "value": "quimica"}, {"label": "Literatura", "value": "Literatura"}, {"label": "Inglês", "value": "ingles"}, {"label": "Espanhol", "value": "espanhol"}, ], )
if ans == "portugues": print("Processing the file for Português") # Verifique se chegou a esta parte file_response = read_file("Enviar") file_name = file_response.name
else: display("Selecione uma opção válida", size='medium')
display, file_response and read_multiple_choice are from a library of my work that I'm using. and that part of the code where you use this is working perfectly.
Thanks for the help!