Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import docx, os, glob
- finaldocname = 'Midterm-All-Questions.docx'
- finaldoc=docx.Document()
- docstoworkon = glob.glob('*.docx')
- if finaldocname in docstoworkon:
- docstoworkon.remove(finaldocname) #dont process final doc if it exists
- for f in docstoworkon:
- doc=docx.Document(f)
- fullText=[]
- for para in doc.paragraphs:
- fullText.append(para.text) #generates a long text list
- # finaldoc.styles = doc.styles
- for l in fullText:
- # if l=='u'\n'':
- if '#' in l:
- print('We got here!')
- if '#1 ' not in l: #check last two characters to see if this is the first question
- finaldoc.add_section() #only add a page break between questions
- finaldoc.add_paragraph(l)
- # finaldoc.add_page_break
- # finaldoc.add_page_break
- finaldoc.save(finaldocname)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement