Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support replacing docx text within embedded tables #1120

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions ooxml/XWPF/Usermodel/XWPFDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,25 @@ private void FindAndReplaceTextInParagraph(XWPFParagraph paragraph, string oldVa
}
}
}

private void FindAndReplaceTextInTable(XWPFTable table, string oldValue, string newValue)
{
foreach (var row in table.Rows)
{
foreach (var cell in row.GetTableCells())
{
foreach (var innerTable in cell.Tables)
{
FindAndReplaceTextInTable(innerTable, oldValue, newValue);
}
foreach (var paragraph in cell.Paragraphs)
{
FindAndReplaceTextInParagraph(paragraph, oldValue, newValue);
}
}
}
}

public void FindAndReplaceText(string oldValue, string newValue)
{
foreach (var paragraph in this.Paragraphs)
Expand All @@ -1930,17 +1949,9 @@ public void FindAndReplaceText(string oldValue, string newValue)

foreach (var table in this.Tables)
{
foreach (var row in table.Rows)
{
foreach (var cell in row.GetTableCells())
{
foreach (var paragraph in cell.Paragraphs)
{
FindAndReplaceTextInParagraph(paragraph, oldValue, newValue);
}
}
}
FindAndReplaceTextInTable(table, oldValue, newValue);
}

foreach (var footer in this.FooterList)
{
foreach (var paragraph in footer.Paragraphs)
Expand Down
Loading