Home > other >  Consult the python - docx library
Consult the python - docx library

Time:10-01

On the first code
 
The from docx import Document
The from docx. Shared import Length
The from docx. Shared import Pt
The from docx. Enum. The text import WD_ALIGN_PARAGRAPH

Doc=Document () # make a new file


Def setFontName (x) : # x is a run object
X.f ont. Name="Times New Roman"

Def setFontSize (x, size) :
X.f ont. Size=Pt (size)

Def setLineSpacing (x) : # x is a handle to a paragraph
X.p aragraph_format. Line_spacing=Pt (18)

Def setAlignment (x) :
X.p aragraph_format. Alignment=WD_ALIGN_PARAGRAPH. The JUSTIFY

P=[]
R=[]
Ac=input (' introduction content:)
Kc=input (' keywords content:)
B=input (' body content:)
Wc=input (' reference:)

PC=[' Abstract ', ac, 'Key Words', kc, b,' Work Cites, wc]
For I in range (7) :
# the Abstract ac Keywords kc Body Workcites wc
P.a ppend (doc. Add_paragraph ())
Of state Richard armitage ppend (p [I] add_run (PC) [I])
[I] setFontName (r)

For I in,3,4,6 (1) :
SetLineSpacing (p [I])
SetAlignment (p [I])
SetFontSize (r [I], 12)

For I in,2,5 (0) :
SetFontSize (r [I], 16)

Doc. Save (' eg. Docx)

In fact the main is I can't use this library is generated with this word document has a lot of down arrow, I hope to put them all into a carriage return, don't know how to change

I want to reach the purpose is to generate the documentation as we play their own kind, the last line is not aligned on both ends, instead of on the left (I think you know what I mean)
Just like this:

Strives for the big help, thank you!
I think a lot about this library are basically translation of official documents, I don't really understand the official document (apparently didn't tell me the situation), by the way, put the document address
https://python-docx.readthedocs.io/en/latest/

CodePudding user response:

Vegetables chicken passing,
I also use the library recently, add_paragraph () is the left arrow? Down arrow is, \ n? ,
If you don't sections of input a try? Don't use cycle, see if the problem out what's missing in loop,
  • Related