I need to save the extracted data in the same format, Arial font size 12.
Currently the code does not follow a pattern of font and size.
I tried using the utf-8 command and it didn’t work.
df_conversas = pd.DataFrame({'Nomes': nomes_conversas})
df_conversas.to_excel('conversas.xlsx', encoding='utf-8', index=False)
>Solution :
You can use ExcelWriter with an xlsxwriter engine :
df_conversas = pd.DataFrame({"Nomes": ["foo", "bar", "baz", "qux"]})
with pd.ExcelWriter("conversas.xlsx", engine="xlsxwriter") as writer:
df_conversas.to_excel(writer, sheet_name="Sheet1", index=False)
workbook = writer.book
workbook.formats[0].set_font_name("Arial")
workbook.formats[0].set_font_size(12)
header_format = workbook.add_format(
{"font_name": "Arial", "font_size": 12, "bold": True}
)
writer.sheets["Sheet1"].write(0, 0, "Nomes", header_format)
#if you have more than a column, use this :
#for idx, col in enumerate(df_conversas.columns):
# writer.sheets["Sheet1"].write(0, idx, col, header_format)
Output :
