-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Xiaoqi Zhao
committed
Dec 10, 2023
1 parent
9e671e9
commit ac62a6b
Showing
14 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-1_use-section_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
8 changes: 8 additions & 0 deletions
8
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-1_use-section_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
19 changes: 19 additions & 0 deletions
19
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-2_section-divider.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+35.7 KB
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-3_2.docx
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-3_paper-size_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
42 changes: 42 additions & 0 deletions
42
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-3_paper-size_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+35.7 KB
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-4_1.docx
Binary file not shown.
Binary file added
BIN
+35.7 KB
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-4_2.docx
Binary file not shown.
14 changes: 14 additions & 0 deletions
14
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-4_orientation_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
16 changes: 16 additions & 0 deletions
16
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-4_orientation_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+35.7 KB
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-5.docx
Binary file not shown.
23 changes: 23 additions & 0 deletions
23
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-5_margin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
12 changes: 12 additions & 0 deletions
12
part2_Use-Python-in-Office/ch07_work-with-word/7-11_page-setup/7-11-6_gutter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |