Skip to content

Commit a622807

Browse files
author
Steve Canny
committed
docs: add quickstart and styles pages
1 parent 752314e commit a622807

File tree

9 files changed

+550
-113
lines changed

9 files changed

+550
-113
lines changed
-11.3 KB
Loading

docs/api/table.rst

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@ Table objects
66

77
Table objects are constructed using the ``add_table()`` method on |Document|.
88

9-
Protocol example::
10-
11-
table = document.add_table(rows=2, cols=2)
12-
top_left_cell = table.cell(0, 0)
13-
top_left_cell.text = 'foobar'
14-
15-
# OR
16-
17-
table = document.add_table(rows=1, cols=2)
18-
table.style = 'LightShading-Accent1'
19-
header_cells = table.rows[0].cells
20-
header_cells[0].text = 'Qty'
21-
header_cells[1].text = 'Desc'
22-
for item in items:
23-
row_cells = table.rows.add().cells
24-
row_cells[0].text = str(item.qty)
25-
row_cells[2].text = item.desc
26-
279

2810
.. currentmodule:: docx.table
2911

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
8484
.. |Emu| replace:: :class:`.Emu`
8585
86+
.. |False| replace:: ``False``
87+
8688
.. |InlineShape| replace:: :class:`.InlineShape`
8789
8890
.. |InlineShapes| replace:: :class:`.InlineShapes`
@@ -113,6 +115,8 @@
113115
114116
.. |Text| replace:: :class:`Text`
115117
118+
.. |True| replace:: ``True``
119+
116120
.. |ValueError| replace:: :class:`ValueError`
117121
"""
118122

docs/dev/analysis/features/run-properties.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,6 @@ applying run-level properties::
2626
None
2727

2828

29-
Acceptance tests
30-
----------------
31-
32-
::
33-
34-
Feature: Apply bold or italic to run
35-
In order to apply emphasis to a particular word or phrase in a paragraph
36-
As a python-docx developer
37-
I need a way to query and set bold and italic on a run
38-
39-
Scenario: Apply bold to a run
40-
Given a run
41-
When I assign True to its bold property
42-
Then the run appears in bold typeface
43-
44-
Scenario: Remove bold from a run
45-
Given a run having bold set on
46-
When I assign None to its bold property
47-
Then the run appears with its inherited bold setting
48-
49-
Scenario: Set bold off unconditionally
50-
Given a run
51-
When I assign False to its bold property
52-
Then the run appears without bold regardless of its style hierarchy
53-
54-
5529
Specimen XML
5630
------------
5731

docs/dev/analysis/features/table.rst

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,6 @@ Table
33
=====
44

55

6-
Overview
7-
--------
8-
9-
10-
Open questions
11-
--------------
12-
13-
* Where do table styles fit in? Probably best not to count on a particular
14-
table style being present in the package.
15-
16-
* What about ranges? Why is that a good idea?
17-
18-
19-
Table access protocol
20-
---------------------
21-
22-
::
23-
24-
>>> table = document.tables[idx]
25-
>>> # OR
26-
>>> for block_item in document.content:
27-
... if isinstance(block_item, _Table):
28-
... ..do table-y things..
29-
30-
31-
Candidate Protocol
32-
------------------
33-
34-
::
35-
36-
>>> table = body.add_table(rows=1, cols=2)
37-
>>> header_cells = table.rows[0].cells
38-
>>> header_cells[0].text = 'Foo Name'
39-
>>> header_cells[1].text = 'Bar Value'
40-
>>> for obj in data_records:
41-
... row_cells = table.add_row().cells
42-
... row_cells[0].text = obj.str_fld_a
43-
... row_cells[1].text = str(obj.int_fld_b)
44-
...
45-
46-
47-
Other protocol notions
48-
----------------------
49-
50-
::
51-
52-
>>> cell = table.cell(0, 0)
53-
>>> p = cell.content[0]
54-
>>> p.text = 'foobar'
55-
>>> p = cell.content.add_paragraph('barfoo')
56-
>>> p.text
57-
'barfoo'
58-
59-
606
MS API
617
------
628

docs/index.rst

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,34 @@ Here's an example of what |docx| can do:
2929
|img| ::
3030

3131
from docx import Document
32+
from docx.shared import Inches
3233

3334
document = Document()
3435

3536
document.add_heading('Document Title', 0)
36-
document.add_paragraph('A plain paragraph.')
37+
38+
p = document.add_paragraph('A plain paragraph having some ')
39+
p.add_run('bold').bold = True
40+
p.add_run(' and some ')
41+
p.add_run('italic.').italic = True
3742

3843
document.add_heading('Heading, level 1', level=1)
3944
document.add_paragraph('Intense quote', style='IntenseQuote')
4045

41-
document.add_bullet('first item in unordered list')
42-
document.add_list_item('first item in ordered list')
46+
document.add_paragraph(
47+
'first item in unordered list', style='ListBullet'
48+
)
49+
document.add_paragraph(
50+
'first item in ordered list', style='ListNumber'
51+
)
4352

44-
document.add_picture('monty-truth.png')
53+
document.add_picture('monty-truth.png', width=Inches(1.25))
4554

46-
table = document.add_table(
47-
rows=1, cols=3, table.style='LightShading-Accent1'
48-
)
49-
header_cells = table.rows[0].cells
50-
header_cells[0].text = 'Qty'
51-
header_cells[1].text = 'Id'
52-
header_cells[2].text = 'Desc'
55+
table = document.add_table(rows=1, cols=3)
56+
hdr_cells = table.rows[0].cells
57+
hdr_cells[0].text = 'Qty'
58+
hdr_cells[1].text = 'Id'
59+
hdr_cells[2].text = 'Desc'
5360
for item in recordset:
5461
row_cells = table.add_row().cells
5562
row_cells[0].text = str(item.qty)
@@ -69,10 +76,10 @@ User Guide
6976
:maxdepth: 1
7077

7178
user/install
79+
user/quickstart
7280
user/documents
7381
user/api-concepts
7482
user/styles
75-
user/tables
7683
user/shapes
7784
user/text
7885

0 commit comments

Comments
 (0)