Word-Generierung implementiert
This commit is contained in:
parent
05811c6579
commit
df7b16c177
3 changed files with 104 additions and 17 deletions
|
|
@ -227,9 +227,9 @@
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1684368507446" ID="ID_1735162824" MODIFIED="1684521700693" POSITION="right" TEXT="Python-Skript">
|
||||
<icon BUILTIN="hourglass"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684368529445" ID="ID_676425093" MODIFIED="1684521720351" TEXT="Implementierung">
|
||||
<node COLOR="#338800" CREATED="1684368529445" ID="ID_676425093" MODIFIED="1684534447099" TEXT="Implementierung">
|
||||
<arrowlink DESTINATION="ID_1966384514" ENDARROW="Default" ENDINCLINATION="-105;-9;" ID="Arrow_ID_1306849550" STARTARROW="None" STARTINCLINATION="-105;-9;"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1684425212214" ID="ID_426224894" MODIFIED="1684528331459" TEXT="SoSci-Definitionen einlesen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1684425286586" ID="ID_1263838545" MODIFIED="1684524021048" TEXT="alle <question>-Elemente aufsammeln">
|
||||
|
|
@ -292,17 +292,27 @@
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684425268727" ID="ID_1433452218" MODIFIED="1684521730288" TEXT="Word-Content generieren">
|
||||
<icon BUILTIN="full-3"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1684425436481" ID="ID_956778724" MODIFIED="1684425441508" TEXT="das Word-Dokument öffnen"/>
|
||||
<node CREATED="1684425442736" ID="ID_197631012" MODIFIED="1684427181758" TEXT="die mehrstufige Liste traversieren"/>
|
||||
<node CREATED="1684425463349" ID="ID_353388703" MODIFIED="1684425494890" TEXT="auf jedem Block-Element eine polymorphe render(wordDocument)-Funktion aufrufen"/>
|
||||
<node CREATED="1684425501667" ID="ID_343903112" MODIFIED="1684425508752" TEXT="Word-Dokument unter neuem Namen speichern"/>
|
||||
<node COLOR="#338800" CREATED="1684425268727" ID="ID_1433452218" MODIFIED="1684534445682" TEXT="Word-Content generieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1684425436481" ID="ID_956778724" MODIFIED="1684531990487" TEXT="das Word-Dokument öffnen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684425442736" ID="ID_197631012" MODIFIED="1684534442728" TEXT="die mehrstufige Liste traversieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684425463349" ID="ID_353388703" MODIFIED="1684534443960" TEXT="auf jedem Block-Element eine polymorphe render(wordDocument)-Funktion aufrufen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684425501667" ID="ID_343903112" MODIFIED="1684531993682" TEXT="Word-Dokument unter neuem Namen speichern">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684368533131" ID="ID_843847965" MODIFIED="1684368539206" TEXT="Test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684368533131" ID="ID_843847965" MODIFIED="1684534448489" TEXT="Test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1684534449512" ID="ID_586598980" MODIFIED="1684534458241" TEXT="sieht richtig aus">
|
||||
<icon BUILTIN="ksmiletris"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1684368546729" ID="ID_1056322615" MODIFIED="1684368551424" POSITION="right" TEXT="Anwendung">
|
||||
|
|
|
|||
|
|
@ -50,4 +50,4 @@ for c in range(1,6):
|
|||
table.cell(1,0).paragraphs[0].text = "IST"
|
||||
table.cell(2,0).paragraphs[0].text = "SOLL"
|
||||
|
||||
document.save('Mist.docx')
|
||||
#document.save('Mist.docx')
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
import sys
|
||||
from xml.etree import ElementTree
|
||||
from docx import Document
|
||||
from demo import document
|
||||
|
||||
|
||||
|
||||
#-----------------------SETUP
|
||||
|
|
@ -24,7 +27,7 @@ def convertSosci2Word():
|
|||
# Schritt-2 : die Fragen in der Reihenfolge vom Questionaire
|
||||
questionaire = buildQuestionaire(questions)
|
||||
## TODO
|
||||
# Schritt-3 : Questionaire in das Word-Dokument ausgeben
|
||||
renderContentToWord(questionaire)
|
||||
## TODO
|
||||
|
||||
|
||||
|
|
@ -40,6 +43,10 @@ class QuestionElement:
|
|||
|
||||
def dump(self):
|
||||
return self.dumpBasis("Basis")
|
||||
|
||||
|
||||
def render(self, document):
|
||||
pass # macht nichts in der Basisklasse
|
||||
|
||||
|
||||
|
||||
|
|
@ -64,6 +71,28 @@ class LikertItem(QuestionElement):
|
|||
+ "\nItems: " + str(list("(%d,%s)" % (c,t) for c,t in self.items))
|
||||
)
|
||||
|
||||
def render(self, document):
|
||||
questionText = self.desc + ": " + self.title
|
||||
document.add_paragraph(questionText, style='Fragebogen-Item')
|
||||
#
|
||||
# Tabelle mit den Antwortmöglichkeiten
|
||||
cntLabels = len(self.labels)
|
||||
cntItems = len(self.items)
|
||||
table = document.add_table(rows=cntItems+1, cols=cntLabels+1)
|
||||
# gesammte Tabelle mit dem korrekten Style auszeichnen
|
||||
for r in table.rows:
|
||||
for c in r.cells:
|
||||
c.paragraphs[0].style = 'Frabebogen-Wert'
|
||||
# alle Inhalts-Spalten ausfüllen
|
||||
# in die Kopfzeile kommt das richtige Label
|
||||
# in die Inhaltsfelder ein Symbol für das Antwort-Kästchen
|
||||
for c in range(1, cntLabels+1):
|
||||
table.cell(0,c).paragraphs[0].text = self.labels[c-1][1]
|
||||
for r in range(1, cntItems+1):
|
||||
table.cell(r,c).paragraphs[0].text = '□'
|
||||
#
|
||||
for r in range(1, cntItems+1):
|
||||
table.cell(r,0).paragraphs[0].text = self.items[r-1][1]
|
||||
|
||||
|
||||
|
||||
|
|
@ -81,6 +110,24 @@ class SelectItem(QuestionElement):
|
|||
return ( self.dumpBasis('Select')
|
||||
+ "\nItems: " + str(list("(%d,%s)" % (c,t) for c,t in self.items))
|
||||
)
|
||||
|
||||
def render(self, document):
|
||||
questionText = self.title
|
||||
document.add_paragraph(questionText, style='Fragebogen-Item')
|
||||
#
|
||||
# Tabelle mit den Antwortmöglichkeiten
|
||||
cntItems = len(self.items)
|
||||
table = document.add_table(rows=cntItems, cols=2)
|
||||
# gesammte Tabelle mit dem korrekten Style auszeichnen
|
||||
for r in table.rows:
|
||||
for c in r.cells:
|
||||
c.paragraphs[0].style = 'Frabebogen-Wert'
|
||||
# alle Inhalts-Spalten ausfüllen
|
||||
# in die Inhaltsfelder links der Fragetext, rechts der Code-Wert
|
||||
for r in range(0, cntItems):
|
||||
table.cell(r,0).paragraphs[0].text = self.items[r][1] # text
|
||||
table.cell(r,1).paragraphs[0].text = str(self.items[r][0]) # code
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -97,6 +144,11 @@ class TextElement(QuestionElement):
|
|||
return ( self.dumpBasis('Text')
|
||||
+ "\nText: " + self.text
|
||||
)
|
||||
|
||||
def render(self, document):
|
||||
document.add_paragraph(self.desc, style='Überschrift-Anhang 3')
|
||||
if self.text != None:
|
||||
document.add_paragraph(self.text, style='Body Text')
|
||||
|
||||
|
||||
|
||||
|
|
@ -158,21 +210,46 @@ def buildQuestionaire(questions):
|
|||
continue # die erste Seite enthält den Einführungstext. Den fügen wir später manuell ein
|
||||
#
|
||||
info = page.find('info').text
|
||||
print('Seite: %s' % info)
|
||||
questionsOnThisPage = []
|
||||
for quest in page.findall('question'):
|
||||
questionID = quest.get('id')
|
||||
print(questionID)
|
||||
element = questions[questionID]
|
||||
print(element.dump())
|
||||
questionsOnThisPage.append(element)
|
||||
|
||||
questionaire.append((info, questionsOnThisPage))
|
||||
#
|
||||
print(questionaire)
|
||||
return questionaire
|
||||
|
||||
|
||||
|
||||
def renderContentToWord(questionaire):
|
||||
#
|
||||
print('Integrate content in Word file "%s"....' % WORD_TEMPLATE)
|
||||
document = Document('Thesis-Fragebogen.docx')
|
||||
#
|
||||
renderQuestionaireTitle(document)
|
||||
for pageInfo, elements in questionaire:
|
||||
renderPageTitle(document, pageInfo)
|
||||
for element in elements:
|
||||
print(element.dump())
|
||||
element.render(document)
|
||||
|
||||
print('Writing modified Word file as "%s"....' % WORD_OUTPUT)
|
||||
document.save(WORD_OUTPUT)
|
||||
#
|
||||
|
||||
# erzeugt ein neues Hauptkapitel im Anhang für den Fragebogen
|
||||
def renderQuestionaireTitle(document):
|
||||
document.add_paragraph('Fragebogen (TODO Import)', style='Überschrift-Anhang 1')
|
||||
|
||||
|
||||
# erzeugt einen Abschnitt im Anhang für die jeweilige Seite des Fragebogens
|
||||
def renderPageTitle(document, title):
|
||||
document.add_paragraph(title, style='Überschrift-Anhang 2')
|
||||
|
||||
|
||||
|
||||
|
||||
# ---- Hilfsfunktionen
|
||||
|
||||
def __err(text):
|
||||
|
|
|
|||
Loading…
Reference in a new issue