Skip to content

Commit

Permalink
7-11 part 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoqi Zhao committed Dec 10, 2023
1 parent 9e671e9 commit ac62a6b
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 0 deletions.
Binary file modified Python-with-Office-Video_Covers.pptx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from docx import Document
doc = Document()

print(type(doc))

print(type(doc.sections))

section = doc.sections[0]

print(type(section))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from docx import Document
doc = Document()

section1 = doc.add_section()

section2 = doc.add_section()

print(len(doc.sections))
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from docx import Document
from docx.enum.section import WD_SECTION_START

doc = Document()

s1 = doc.add_section()
print(s1.start_type)

s2 = doc.add_section(WD_SECTION_START.NEW_PAGE)
print(s2.start_type)

s3 = doc.add_section(WD_SECTION_START.CONTINUOUS)
print(s3.start_type)

s4 = doc.add_section(WD_SECTION_START.EVEN_PAGE)
print(s4.start_type)

s5 = doc.add_section(WD_SECTION_START.ODD_PAGE)
print(s5.start_type)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from docx import Document
doc = Document()

section = doc.sections[0]

# python-docx is using "Letter" size as default

print(section.page_width.cm)

print(section.page_height.mm)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from docx import Document
from docx.shared import Cm

doc = Document()

section = doc.sections[0]

# python-docx is using "Letter" size as default

print(section.page_width.cm)

print(section.page_height.mm)

# set Page size to A4

section.page_width = Cm(21.0)
section.page_height = Cm(29.7)

print(section.page_width.cm)

print(section.page_height.mm)

# set Page size to Legal

section.page_width = Cm(21.59)
section.page_height = Cm(35.56)

print(section.page_width.cm)

print(section.page_height.mm)

# set Page size to non-standard

section.page_width = Cm(11.59)
section.page_height = Cm(25.56)

print(section.page_width.cm)

print(section.page_height.mm)


doc.save("./7-11-3_2.docx")
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from docx import Document
from docx.enum.section import WD_ORIENTATION

doc = Document()

section = doc.sections[0]

print(section.orientation)

section.orientation = WD_ORIENTATION.LANDSCAPE

print(section.orientation)

doc.save("./7-11-4_1.docx")
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from docx import Document
from docx.enum.section import WD_ORIENTATION

doc = Document()

section = doc.sections[0]

section.orientation = WD_ORIENTATION.LANDSCAPE

width = section.page_width
height = section.page_height

section.page_width = height
section.page_height = width

doc.save("./7-11-4_2.docx")
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from docx import Document
from docx.shared import Cm

doc = Document()

section = doc.sections[0]

print(section.top_margin.cm)
print(section.bottom_margin.cm)
print(section.left_margin.cm)
print(section.right_margin.cm)

section.top_margin = Cm(2)
section.bottom_margin = Cm(1)
section.left_margin = Cm(1.5)
section.right_margin = Cm(4)

print(section.top_margin.cm)
print(section.bottom_margin.cm)
print(section.left_margin.cm)
print(section.right_margin.cm)

doc.save("./7-11-5.docx")
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from docx import Document
from docx.shared import Cm

doc = Document()

section = doc.sections[0]

print(section.gutter.cm)

section.gutter = Cm(1.0)

print(section.gutter.cm)

0 comments on commit ac62a6b

Please sign in to comment.