python-docx installiert / erste Experimente
- Beispiel-Dokument generieren - bestehendes Dokument analysieren Aus Thesis-Fragebogen.docx folgende Bestände extrahiert (als Referenz) - document.xml - styles.xml
This commit is contained in:
parent
5252798b4f
commit
05cf32c1d1
7 changed files with 8833 additions and 3 deletions
2
sosci2word/.gitignore
vendored
Normal file
2
sosci2word/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*.docx
|
||||
.pydevproject
|
||||
1
sosci2word/Ichthyo-Pp.png
Symbolic link
1
sosci2word/Ichthyo-Pp.png
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
/Lager/Halde/Ecke/Bilder/ID/Ichthyo-Pp.png
|
||||
7144
sosci2word/Thesis-Fragebogen.document.xml
Normal file
7144
sosci2word/Thesis-Fragebogen.document.xml
Normal file
File diff suppressed because it is too large
Load diff
1454
sosci2word/Thesis-Fragebogen.styles.xml
Normal file
1454
sosci2word/Thesis-Fragebogen.styles.xml
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -19,7 +19,7 @@
|
|||
</html>
|
||||
</richcontent>
|
||||
<font NAME="SansSerif" SIZE="25"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684368358553" ID="ID_1393333722" MODIFIED="1684368436861" POSITION="right">
|
||||
<node COLOR="#338800" CREATED="1684368358553" FOLDED="true" ID="ID_1393333722" MODIFIED="1684370541179" POSITION="right">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
|
|
@ -34,10 +34,79 @@
|
|||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#435e98" CREATED="1684369626336" ID="ID_1930947145" MODIFIED="1684370533498" TEXT="aktuelle Version: v0.8.11">
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1684369635007" ID="ID_385316610" MODIFIED="1684369661401" TEXT="installierbar per PIP">
|
||||
<icon BUILTIN="forward"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684368494840" ID="ID_1680262238" MODIFIED="1684368502922" POSITION="right" TEXT="Vor-Analyse (Hermann)">
|
||||
<node CREATED="1684369640102" ID="ID_1176431171" MODIFIED="1684369645289" TEXT="alternativ als Egg"/>
|
||||
<node CREATED="1684369645669" ID="ID_754654159" MODIFIED="1684369653536" TEXT="oder per Tarball"/>
|
||||
</node>
|
||||
<node CREATED="1684369745677" ID="ID_407462667" MODIFIED="1684369755771">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<font face="Monospaced">pip3 install python-docx</font>
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="idea"/>
|
||||
<node COLOR="#338800" CREATED="1684369771059" ID="ID_637583003" MODIFIED="1684369773883" TEXT="Successfully installed lxml-4.9.2 python-docx-0.8.11">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684370518324" ID="ID_1450149158" MODIFIED="1684370528357" TEXT="Demo-Beispiel aus der Doku: läuft!">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1684368494840" ID="ID_1680262238" MODIFIED="1684377529586" POSITION="right" TEXT="Vor-Analyse (Hermann)">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1684377232205" ID="ID_1958647529" MODIFIED="1684377240495" TEXT="Word-Dokument">
|
||||
<node CREATED="1684377241659" ID="ID_211996471" MODIFIED="1684377246663" TEXT="analysieren">
|
||||
<node COLOR="#338800" CREATED="1684377247978" ID="ID_274709233" MODIFIED="1684377253589" TEXT="XML direkt anschauen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1684377255306" ID="ID_1161459111" MODIFIED="1684377259053" TEXT="document.xml"/>
|
||||
<node CREATED="1684377259491" ID="ID_1480247945" MODIFIED="1684377261252" TEXT="style.xml"/>
|
||||
</node>
|
||||
<node CREATED="1684377262817" ID="ID_812231772" MODIFIED="1684377270683" TEXT="per python-docx">
|
||||
<node CREATED="1684377271847" ID="ID_1437160491" MODIFIED="1684377305927" TEXT="schwierig...">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
<node CREATED="1684377292708" ID="ID_23107409" MODIFIED="1684377293640" TEXT="nur reduziertes Feature-Set"/>
|
||||
<node CREATED="1684377294156" ID="ID_481765281" MODIFIED="1684377303524" TEXT="weitgehend undokumentiert"/>
|
||||
</node>
|
||||
<node CREATED="1684377307327" ID="ID_308902955" MODIFIED="1684377320981" TEXT="Nur Liste der Paragraphen funktioniert"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1684377338918" ID="ID_350207560" MODIFIED="1684377343466" TEXT="Experimente">
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684377348301" ID="ID_1351208320" MODIFIED="1684377523104" TEXT="gewünschte Struktur generieren">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1684377363350" ID="ID_1722191248" MODIFIED="1684377417600" TEXT="Paragraph Level-1">
|
||||
<node CREATED="1684377418572" ID="ID_789579724" MODIFIED="1684377419307" TEXT="Überschrift-Anhang-1"/>
|
||||
</node>
|
||||
<node CREATED="1684377374641" ID="ID_656323449" MODIFIED="1684377423139" TEXT="Paragraph Level-2">
|
||||
<node CREATED="1684377424067" ID="ID_1421156201" MODIFIED="1684377425518" TEXT="Überschrift-Anhang-2"/>
|
||||
<node CREATED="1684377428482" ID="ID_260102370" MODIFIED="1684377432598" TEXT="Name der Seite"/>
|
||||
</node>
|
||||
<node CREATED="1684377374641" ID="ID_1529315456" MODIFIED="1684377441772" TEXT="Paragraph Level-3">
|
||||
<node CREATED="1684377424067" ID="ID_287818753" MODIFIED="1684377444684" TEXT="Überschrift-Anhang-3"/>
|
||||
<node CREATED="1684377428482" ID="ID_1765680266" MODIFIED="1684377451459" TEXT="Fragen zu den ...."/>
|
||||
</node>
|
||||
<node CREATED="1684377453023" ID="ID_86415285" MODIFIED="1684377463473" TEXT="Item-Paragraph">
|
||||
<node CREATED="1684377464360" ID="ID_1556523011" MODIFIED="1684377467816" TEXT="Fragebogen-Item"/>
|
||||
<node CREATED="1684377469205" ID="ID_582132926" MODIFIED="1684377473847" TEXT="Frage-Text"/>
|
||||
</node>
|
||||
<node CREATED="1684377476614" ID="ID_1573790382" MODIFIED="1684377479271" TEXT="Tabelle einfügen">
|
||||
<node CREATED="1684377484011" ID="ID_560492731" MODIFIED="1684377492777" TEXT="3 Zeilen, 6 Spalten"/>
|
||||
<node CREATED="1684377501825" ID="ID_689639952" MODIFIED="1684377508492" TEXT="1. Zeile : Überschriften"/>
|
||||
<node CREATED="1684377514623" ID="ID_747959819" MODIFIED="1684377521302" TEXT="Soll / IST / Kästchen"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1684368507446" ID="ID_1735162824" MODIFIED="1684368541488" POSITION="right" TEXT="Python-Skript">
|
||||
<icon BUILTIN="hourglass"/>
|
||||
|
|
@ -58,10 +127,101 @@
|
|||
<node CREATED="1684368381438" ID="ID_536028682" MODIFIED="1684368562213" POSITION="left" TEXT="Word verstehen">
|
||||
<font NAME="SansSerif" SIZE="16"/>
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1684371396181" ID="ID_1494643844" MODIFIED="1684371402030" TEXT="ein Wort-Dokument">
|
||||
<node CREATED="1684371402940" ID="ID_775127417" MODIFIED="1684371610767" TEXT="is a ZIP-compressed folder">
|
||||
<node CREATED="1684371633747" ID="ID_315178960" MODIFIED="1684371642943" TEXT="holds ressources"/>
|
||||
<node CREATED="1684371709763" ID="ID_703260300" MODIFIED="1684371713790" TEXT="+ metadata"/>
|
||||
<node CREATED="1684371643252" ID="ID_1429386608" MODIFIED="1684371645535" TEXT="definitions"/>
|
||||
<node CREATED="1684371701661" ID="ID_69268008" MODIFIED="1684371706423" TEXT="styles"/>
|
||||
<node CREATED="1684371647211" ID="ID_1648598144" MODIFIED="1684371649870" TEXT="the main document"/>
|
||||
</node>
|
||||
<node CREATED="1684371413811" ID="ID_1307162677" MODIFIED="1684371728813" TEXT="the main document">
|
||||
<node CREATED="1684371729449" ID="ID_252182702" MODIFIED="1684371734004" TEXT="is an XML-document"/>
|
||||
<node CREATED="1684371734712" ID="ID_1561962743" MODIFIED="1684371745264" TEXT="holds metadata"/>
|
||||
<node CREATED="1684371745750" ID="ID_1039576961" MODIFIED="1684371749874" TEXT="+ actual content"/>
|
||||
</node>
|
||||
<node CREATED="1684371422890" ID="ID_546163362" MODIFIED="1684371752987" TEXT="actual Content">
|
||||
<node CREATED="1684371432720" ID="ID_1123773556" MODIFIED="1684371453578" TEXT="a sequence of Paragraphs"/>
|
||||
<node CREATED="1684372227175" ID="ID_821942243" MODIFIED="1684372243007" TEXT="(or other block-level elements)">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Images, Tables....
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
</node>
|
||||
<node CREATED="1684371477714" ID="ID_513980953" MODIFIED="1684371513122">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
each <b>Paragraph</b>
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<node CREATED="1684371481997" ID="ID_1253152554" MODIFIED="1684371485957" TEXT="has a style"/>
|
||||
<node CREATED="1684371486953" ID="ID_1787404624" MODIFIED="1684371496582" TEXT="has content in several Runs"/>
|
||||
<node CREATED="1684372247214" ID="ID_1055426349" MODIFIED="1684372262902" TEXT="(or other inline elements)">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
embedded images, frames, embedded tables
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
</node>
|
||||
<node CREATED="1684371497069" ID="ID_1839965384" MODIFIED="1684371506717">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
each <b>Run</b>
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<node CREATED="1684371515717" ID="ID_1563699272" MODIFIED="1684371522704" TEXT="has a character style"/>
|
||||
<node CREATED="1684371523180" ID="ID_1767406497" MODIFIED="1684371527775" TEXT="has local (hard) formatting"/>
|
||||
<node CREATED="1684371528243" ID="ID_1649997235" MODIFIED="1684371538414" TEXT="holds a sequence of actual Text"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1684368386013" ID="ID_271244982" MODIFIED="1684368562213" POSITION="left" TEXT="Python verstehen">
|
||||
<font NAME="SansSerif" SIZE="16"/>
|
||||
<icon BUILTIN="idea"/>
|
||||
<node COLOR="#435e98" CREATED="1684369795005" ID="ID_1730265194" MODIFIED="1684369882498">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Modul <b>python-doxc</b>
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<edge COLOR="#5856c4" STYLE="linear"/>
|
||||
<cloud COLOR="#ccd0eb"/>
|
||||
<font NAME="SansSerif" SIZE="14"/>
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1684369841851" ID="ID_1686589099" MODIFIED="1684369845472" TEXT="Doku">
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1684369895137" ID="ID_1453810450" LINK="https://pypi.org/project/python-docx/" MODIFIED="1684369900089" TEXT="pypi.org"/>
|
||||
<node CREATED="1684369901112" ID="ID_1354824178" MODIFIED="1684369907713" TEXT="readthedoks"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1684368462716" HGAP="35" ID="ID_153147470" MODIFIED="1684368481229" POSITION="left" TEXT="Arbeitsdaten" VSHIFT="27">
|
||||
<node CREATED="1684368834508" ID="ID_273513864" MODIFIED="1684368918857" TEXT="ThesisFragebogen.2023-04-19.xml">
|
||||
|
|
|
|||
46
sosci2word/demo.py
Executable file
46
sosci2word/demo.py
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from docx import Document
|
||||
from docx.shared import Inches
|
||||
|
||||
document = Document()
|
||||
|
||||
document.add_heading('Document Title', 0)
|
||||
|
||||
p = document.add_paragraph('A plain paragraph having some ')
|
||||
p.add_run('bold').bold = True
|
||||
p.add_run(' and some ')
|
||||
p.add_run('italic.').italic = True
|
||||
|
||||
document.add_heading('Heading, level 1', level=1)
|
||||
document.add_paragraph('Intense quote', style='Intense Quote')
|
||||
|
||||
document.add_paragraph(
|
||||
'first item in unordered list', style='List Bullet'
|
||||
)
|
||||
document.add_paragraph(
|
||||
'first item in ordered list', style='List Number'
|
||||
)
|
||||
|
||||
document.add_picture('Ichthyo-Pp.png', width=Inches(3))
|
||||
|
||||
records = (
|
||||
(3, '101', 'Spam'),
|
||||
(7, '422', 'Eggs'),
|
||||
(4, '631', 'Spam, spam, eggs, and spam')
|
||||
)
|
||||
|
||||
table = document.add_table(rows=1, cols=3)
|
||||
hdr_cells = table.rows[0].cells
|
||||
hdr_cells[0].text = 'Qty'
|
||||
hdr_cells[1].text = 'Id'
|
||||
hdr_cells[2].text = 'Desc'
|
||||
for qty, id, desc in records:
|
||||
row_cells = table.add_row().cells
|
||||
row_cells[0].text = str(qty)
|
||||
row_cells[1].text = id
|
||||
row_cells[2].text = desc
|
||||
|
||||
document.add_page_break()
|
||||
|
||||
document.save('demo.docx')
|
||||
23
sosci2word/experiment.py
Executable file
23
sosci2word/experiment.py
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from docx import Document
|
||||
from docx.shared import Inches
|
||||
|
||||
from pprint import pprint
|
||||
|
||||
document = Document('Thesis-Fragebogen.docx')
|
||||
|
||||
for par in document.paragraphs:
|
||||
print(par.text)
|
||||
print("---style||" + par.style.name)
|
||||
print("############")
|
||||
for tab in document.tables:
|
||||
print("...style||" + tab.style.name)
|
||||
pprint(dir(tab.style))
|
||||
# pp = par.part
|
||||
# pprint(dir(pp))
|
||||
# for r in par.runs:
|
||||
# pprint(r.text)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in a new issue