如何在python docx中更改句子的字体样式

时间:2018-06-08 04:19:50

标签: python python-3.x docx python-docx

我们如何在python docx中将字体名称,大小等应用于add_run() 我尝试了以下但它不起作用。

run = Document().add_paragraph().add_run()
font = run.font
font.name = “MS Gothic”
Document().add_paragraph().add_run(“Some random text”)

2 个答案:

答案 0 :(得分:2)

对于每个句子,请尝试以下内容:

 String Var = "SELECT MAX(id) FROM goupe ; ";
     ResultSet vari=st.executeQuery(Var);
     while(vari.next()){
     nombre = vari.getInt("id");}
     String sql = "INSERT INTO Student(name,famillyname,email,password,module,speciality,card,id_goupe)VALUES('"+name+"','"+familly+"','"+email+"','"+pass+"','"+module+"','"+specialite+"','"+card+"','"+nombre+"');";
                st.execute(sql);

答案 1 :(得分:0)

之前已经回答过,您可以查看here,您必须应用样式。我已经测试了下面的内容,它似乎有效。

import docx
document = docx.Document()
run = document.add_paragraph().add_run()
'''Apply style'''
style = document.styles['Normal']
font = style.font
font.name = 'MS Gothic'
font.size = docx.shared.Pt(15)
document.add_paragraph('Some text').add_run()