diff --git a/sosci2word/_README.txt b/sosci2word/_README.txt index 02b20ad..1a6c29b 100644 --- a/sosci2word/_README.txt +++ b/sosci2word/_README.txt @@ -42,10 +42,10 @@ besonders relevant: logisches Format:: Metadaten + verschachtelte Sequenz von _Block_- und _Inline_-Elementen + - Block-Elemente sind: Paragraph, Table, Image, Drawing -- Inline-Elemente sind: Run (=Text-Schnippsel mit einheitlichem Format), Table, Image, Frame +- Inline-Elemente sind: Run (=Text-Schnipsel mit einheitlichem Format), Table, Image, Frame + Sowohl Block-, alsauch Inline-Elemente sind direkt mit einem _Style_ ausgezeichnet. -Dieser kann sowohl _direkte Foramtierung_ umfassen, aber auch auf einen _definierten Style_ +Dieser kann sowohl _direkte Formatierung_ umfassen, aber auch auf einen _definierten Style_ aus dem Stylesheet (``Formatvorlage'') per Name-ID verweisen. [yellow-background]#WIP# @@ -69,6 +69,11 @@ und sofort in Word-Content transformiert wird. Es ergeben sich aber im Detail ei auch noch XML-quoted. - wir haben mehrere Item-Typen, mit einer jeweils anderen Datenstruktur => Polymorphismus +NOTE: es ist mit den gegebenen Mitteln nicht möglich, das Tabellen-Styling zu steuern. + Man könnte der ganzen Tabelle einen Style zuweisen, und man kann den Parahgraphs + in jeder Zelle einen Style zuweisen (oder sie manuell formatieren). Jedoch + kein Zugriff auf Rahmenarten, Cell-Alignment, Shading + Verarbeitungs-Schema ~~~~~~~~~~~~~~~~~~~~ [yellow-background]#(dies ist der Plan zur Implementierung)#: diff --git a/sosci2word/_SoSci2Word.mm b/sosci2word/_SoSci2Word.mm index 2d5de6e..acaedaa 100644 --- a/sosci2word/_SoSci2Word.mm +++ b/sosci2word/_SoSci2Word.mm @@ -64,7 +64,7 @@ - + @@ -80,30 +80,89 @@ - - - - - + + + + + + - + + - + + - + + - + + + + + + + + + + + + + + + + + +

+ ...und nicht die reine Name-ID, die man im document.xml bzw. styles.xml sieht. Da passiert anscheinend eine Übersetzung +

+ +
+
+ + + + + + +

+ styles = document.styles +

+

+ paragraph_styles = [ +

+

+     s for s in styles if s.type == WD_STYLE_TYPE.PARAGRAPH +

+

+ ] +

+

+ for style in paragraph_styles: +

+

+     print(style.name) +

+ +
+ +
+ + + + + @@ -152,7 +211,7 @@ - + diff --git a/sosci2word/experiment.py b/sosci2word/experiment.py index 2755bd0..02260af 100755 --- a/sosci2word/experiment.py +++ b/sosci2word/experiment.py @@ -7,17 +7,47 @@ 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)) +# 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) - +from docx.enum.style import WD_STYLE_TYPE +styles = document.styles +paragraph_styles = [ + s for s in styles if s.type == WD_STYLE_TYPE.PARAGRAPH +] +for style in paragraph_styles: + print(style.name) + +document.add_paragraph('Fragebogen (TODO Import)', style='Überschrift-Anhang 1') +document.add_paragraph('Fragen zur Verzwergung', style='Überschrift-Anhang 2') +document.add_paragraph('Hoffnungslosigkeit', style='Überschrift-Anhang 3') + +document.add_paragraph('Ich könnte mir jeden Tag die Kugel geben', style='Fragebogen-Item') + +table = document.add_table(rows=3, cols=6) + +labels = ['niemals','vielleicht','manchmal','immer', 'sowieso'] + +for r in table.rows: + for c in r.cells: + c.paragraphs[0].style = 'Frabebogen-Wert' + +for c in range(1,6): + table.cell(0,c).paragraphs[0].text = labels[c-1] + table.cell(1,c).paragraphs[0].text = '□' + table.cell(2,c).paragraphs[0].text = '□' + +table.cell(1,0).paragraphs[0].text = "IST" +table.cell(2,0).paragraphs[0].text = "SOLL" + +document.save('Mist.docx')