Skip to content

Commit

Permalink
fix #606
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyqus committed Mar 9, 2024
1 parent 3255844 commit 5428cfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 11 additions & 3 deletions OpenXmlFormats/Wordprocessing/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,21 @@ public CT_SectPr sectPr
this.sectPrField = value;
}
}
public CT_Tbl AddNewTbl()
public CT_Tbl AddNewTbl(int? pos = null)
{
CT_Tbl tbl = new CT_Tbl();
lock (this)
{
this.itemsField.Add(tbl);
this.itemsElementNameField.Add(DocumentBodyItemChoiceType.tbl);
if(pos.HasValue)
{
this.itemsField.Insert(pos.Value, tbl);
this.itemsElementNameField.Insert(pos.Value, DocumentBodyItemChoiceType.tbl);
}
else
{
this.itemsField.Add(tbl);
this.itemsElementNameField.Add(DocumentBodyItemChoiceType.tbl);
}
}
return tbl;
}
Expand Down
8 changes: 4 additions & 4 deletions ooxml/XWPF/Usermodel/XWPFDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,9 @@ public XWPFParagraph GetLastParagraph()
* Create an empty table with one row and one column as default.
* @return a new table
*/
public XWPFTable CreateTable()
public XWPFTable CreateTable(int? pos = null)
{
XWPFTable table = new XWPFTable(ctDocument.body.AddNewTbl(), this);
XWPFTable table = new XWPFTable(ctDocument.body.AddNewTbl(pos), this);
bodyElements.Add(table);
tables.Add(table);
return table;
Expand All @@ -1178,9 +1178,9 @@ public XWPFTable CreateTable()
* @param cols
* @return table
*/
public XWPFTable CreateTable(int rows, int cols)
public XWPFTable CreateTable(int rows, int cols, int? pos = null)
{
XWPFTable table = new XWPFTable(ctDocument.body.AddNewTbl(), this, rows, cols);
XWPFTable table = new XWPFTable(ctDocument.body.AddNewTbl(pos), this, rows, cols);
bodyElements.Add(table);
tables.Add(table);
return table;
Expand Down

0 comments on commit 5428cfd

Please sign in to comment.