Skip to content

Commit

Permalink
fix: #149 KeyError on Document.add_table()
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Canny committed Feb 21, 2015
1 parent 5309b41 commit 280d46a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Release History
---------------

NEXT
++++++++++++++++++

- Fix #149: KeyError on Document.add_table()


0.8.4 (2015-02-20)
++++++++++++++++++

Expand Down
7 changes: 4 additions & 3 deletions docx/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ def add_section(self, start_type=WD_SECTION.NEW_PAGE):
new_sectPr.start_type = start_type
return Section(new_sectPr)

def add_table(self, rows, cols, style='Light Shading Accent 1'):
def add_table(self, rows, cols, style=None):
"""
Add a table having row and column counts of *rows* and *cols*
respectively and table style of *style*. If *style* is |None|, a
table with no style is produced.
respectively and table style of *style*. *style* may be a paragraph
style object or a paragraph style name. If *style* is |None|, the
table inherits the default table style of the document.
"""
table = self._body.add_table(rows, cols)
table.style = style
Expand Down
4 changes: 2 additions & 2 deletions features/doc-add-table.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Feature: Add a table


Scenario: Add a table specifying only row and column count
Given a document having built-in styles
Given a blank document
When I add a 2 x 2 table specifying only row and column count
Then the document contains a 2 x 2 table
And table.style is styles['Light Shading Accent 1']
And table.style is styles['Normal Table']


Scenario: Add a table specifying style
Expand Down

0 comments on commit 280d46a

Please sign in to comment.