diff --git a/demo.docx b/demo.docx new file mode 100644 index 000000000..1164aeedd Binary files /dev/null and b/demo.docx differ diff --git a/demo2.docx b/demo2.docx new file mode 100644 index 000000000..b6a13d888 Binary files /dev/null and b/demo2.docx differ diff --git a/demo2.zip b/demo2.zip new file mode 100644 index 000000000..e2e51f579 Binary files /dev/null and b/demo2.zip differ diff --git a/demo2/[Content_Types].xml b/demo2/[Content_Types].xml new file mode 100644 index 000000000..709ebdda6 --- /dev/null +++ b/demo2/[Content_Types].xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/_rels/.rels b/demo2/_rels/.rels new file mode 100644 index 000000000..32548d423 --- /dev/null +++ b/demo2/_rels/.rels @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/customXml/_rels/item1.xml.rels b/demo2/customXml/_rels/item1.xml.rels new file mode 100644 index 000000000..b4bc8d63c --- /dev/null +++ b/demo2/customXml/_rels/item1.xml.rels @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/customXml/_rels/item2.xml.rels b/demo2/customXml/_rels/item2.xml.rels new file mode 100644 index 000000000..49b7c9474 --- /dev/null +++ b/demo2/customXml/_rels/item2.xml.rels @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/customXml/item1.xml b/demo2/customXml/item1.xml new file mode 100644 index 000000000..b3347e6a4 --- /dev/null +++ b/demo2/customXml/item1.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/demo2/customXml/item2.xml b/demo2/customXml/item2.xml new file mode 100644 index 000000000..c614fb0b3 --- /dev/null +++ b/demo2/customXml/item2.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/demo2/customXml/itemProps1.xml b/demo2/customXml/itemProps1.xml new file mode 100644 index 000000000..c9622b053 --- /dev/null +++ b/demo2/customXml/itemProps1.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/customXml/itemProps2.xml b/demo2/customXml/itemProps2.xml new file mode 100644 index 000000000..81faf6923 --- /dev/null +++ b/demo2/customXml/itemProps2.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/docProps/app.xml b/demo2/docProps/app.xml new file mode 100644 index 000000000..bff53bf88 --- /dev/null +++ b/demo2/docProps/app.xml @@ -0,0 +1,2 @@ + +0235194Microsoft Office Word011falseTitle1false228falsefalse16.0000 \ No newline at end of file diff --git a/demo2/docProps/core.xml b/demo2/docProps/core.xml new file mode 100644 index 000000000..971203e31 --- /dev/null +++ b/demo2/docProps/core.xml @@ -0,0 +1,2 @@ + +python-docxgenerated by python-docxIsaac Baum22013-12-23T23:15:00Z2020-06-20T22:38:00Z \ No newline at end of file diff --git a/demo2/word/_rels/document.xml.rels b/demo2/word/_rels/document.xml.rels new file mode 100644 index 000000000..496722e60 --- /dev/null +++ b/demo2/word/_rels/document.xml.rels @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/word/document.xml b/demo2/word/document.xml new file mode 100644 index 000000000..20fd98989 --- /dev/null +++ b/demo2/word/document.xml @@ -0,0 +1,112 @@ + + + + + + + Document Title + + + + + A plain paragraph having some + + + + bold + + and some + italic. + + + + Heading, level 1 + + + Intense quote + + + first item in unordered list + + first item in ordered list + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Qty + + + + Id + + + + Desc + + + + + 3 + + + 101 + + + Spam + + + + + 7 + + + 422 + + + Eggs + + + + + 4 + + + 631 + + + Spam, spam, eggs, and spam + + + + + + + + + + \ No newline at end of file diff --git a/demo2/word/fontTable.xml b/demo2/word/fontTable.xml new file mode 100644 index 000000000..c95a393f9 --- /dev/null +++ b/demo2/word/fontTable.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/word/media/image1.jpg b/demo2/word/media/image1.jpg new file mode 100644 index 000000000..690c1b9f9 Binary files /dev/null and b/demo2/word/media/image1.jpg differ diff --git a/demo2/word/numbering.xml b/demo2/word/numbering.xml new file mode 100644 index 000000000..1b5da4fc4 --- /dev/null +++ b/demo2/word/numbering.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/word/settings.xml b/demo2/word/settings.xml new file mode 100644 index 000000000..3a909df5e --- /dev/null +++ b/demo2/word/settings.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/word/styles.xml b/demo2/word/styles.xml new file mode 100644 index 000000000..810dd5630 --- /dev/null +++ b/demo2/word/styles.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/word/theme/theme1.xml b/demo2/word/theme/theme1.xml new file mode 100644 index 000000000..113988a69 --- /dev/null +++ b/demo2/word/theme/theme1.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo2/word/webSettings.xml b/demo2/word/webSettings.xml new file mode 100644 index 000000000..a0589f9b4 --- /dev/null +++ b/demo2/word/webSettings.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/docx/document.py b/docx/document.py index 6493c458b..862a98482 100644 --- a/docx/document.py +++ b/docx/document.py @@ -1,5 +1,5 @@ # encoding: utf-8 - +# comment added to bootsielon's repo """|Document| and closely related objects""" from __future__ import absolute_import, division, print_function, unicode_literals diff --git a/myTests.py b/myTests.py new file mode 100644 index 000000000..397109361 --- /dev/null +++ b/myTests.py @@ -0,0 +1,198 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Jun 20 17:06:01 2020 + +@author: ISAAC +""" + +#%% +import os +print(os.getcwd()) +#%% +newpath = 'C:/Users/ISAAC/OneDrive/repos/python-docx' #ASUS/DELL +os.chdir(newpath) +os.getcwd() +#%% +import docx +#%% + +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('schopen.jpg', width=Inches(1.25)) + +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') +#%% +document2=Document('demo2.docx') +#%% +for i,p in enumerate(document.paragraphs): print(i,p.text) +#%% +for i,p in enumerate(document2.paragraphs): print(i,p.text) +#%% +for table in document.tables: + rows = table.rows#print(table.c) + for row in rows: + cells=row.cells + for cell in cells: + print(cell.text) +#%% +for i, table in enumerate(document2.tables): + rows = table.rows#print(table.c) + for j, row in enumerate(rows): + cells=row.cells + for k,cell in enumerate(cells): + print(i,j,k,cell.text) +#%% +for i, table in enumerate(document.tables): + rows = table.rows#print(table.c) + for j, row in enumerate(rows): + cells=row.cells + for k,cell in enumerate(cells): + print(i,j,k,cell.text) +#%% +for table in document.tables: + rows = table.rows#print(table.c) + for row in rows: + cells=row.cells + for cell in cells: + paragraphs= cell.paragraphs + for paragraph in paragraphs: + print(paragraph.text) + #print(paragraphs.text) +#%% +for table in document2.tables: + rows = table.rows#print(table.c) + for row in rows: + cells=row.cells + for cell in cells: + paragraphs= cell.paragraphs + for paragraph in paragraphs: + print(paragraph.text) + #print(paragraphs.text) + +#%% +numtabpars = 0 +for i, table in enumerate(document.tables): + rows = table.rows#print(table.c) + for j, row in enumerate(rows): + cells=row.cells + for k,cell in enumerate(cells): + #print(i,j,k,cell.text) + paragraphs= cell.paragraphs + for m, paragraph in enumerate(paragraphs): + print(i,j,k,m,paragraph.text) + numtabpars=numtabpars+1 +print(numtabpars) + +#%% +numtabpars2 = 0 +for i, table in enumerate(document2.tables): + rows = table.rows#print(table.c) + for j, row in enumerate(rows): + cells=row.cells + for k,cell in enumerate(cells): + #print(i,j,k,cell.text) + paragraphs= cell.paragraphs + for m, paragraph in enumerate(paragraphs): + print(i,j,k,m,paragraph.text) + numtabpars2=numtabpars2+1 +print(numtabpars2) +#%% +print(len(document2.paragraphs)+numtabpars2) +#%% +numpars2=0 +for i,p in enumerate(document2.paragraphs): + print(i,p.text, len(p.text)) + counts = 1 if len(p.text)>0 else 0 + numpars2=numpars2+counts +print(numpars2) +#%% +print(numpars2+numtabpars2) +#%% +#%% +from docx.oxml.xmlchemy import BaseOxmlElement, ZeroOrOne, ZeroOrMore, XmlString, serialize_for_reading +#%% + +p = ZeroOrMore('w:p', successors=('w:sectPr',)) +#%% +openXmlTestString = ''' + +Test string +''' +#%% +lmaf = open("../LMA_prettified.xml", "r",encoding="utf8") +#%% +#CT_Document +from docx.oxml.document import CT_Document, CT_Body +testdocx1=CT_Document(lmaf.read()) + +#%% +#from docx import Document +#lmadocx=Document(lmaf) +#%% +xmls=XmlString(openXmlTestString) +#serialize_for_reading(openXmlTestString) +#%% +from lxml.builder import E + +def CLASS(*args): # class is a reserved word in Python + return {"class":' '.join(args)} + +#%% + +html = page = ( + E.html( # create an Element called "html" + E.head( + E.title("This is a sample document") + ), + E.body( + E.h1("Hello!", CLASS("title")), + E.p("This is a paragraph with ", E.b("bold"), " text in it!"), + E.p("This is another paragraph, with a", "\n ", + E.a("link", href="http://www.python.org"), "."), + E.p("Here are some reserved characters: ."), + etree.XML("

And finally an embedded XHTML fragment.

"), + ) + ) + ) +#%% +print(etree.tostring(page, pretty_print=True)) + diff --git a/schopen.jpg b/schopen.jpg new file mode 100644 index 000000000..690c1b9f9 Binary files /dev/null and b/schopen.jpg differ