Hi,
Hi Brendan,
Table tab = doc.FirstSection.Body.Tables[0];
// Clone last Row 10 times
for (int i = 0; i < 10; i++)
{
Node newRow = tab.LastRow.Clone(true);
tab.AppendChild(newRow);
}
doc.Save(MyDir + @"16.1.0.docx");
- Your input document
- Aspose.Words generated output document showing the undesired behavior
- Your expected document which shows the correct output. Please create this document using Microsoft Word application.
- Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.
Thanks. One more thing your example doesn’t include. How do i get the current row? e.Document.ParentNode.ParentNode doesn’t work.
Ok, I figured this out. I modified the table after the whole document is created, rather than modifying it in the FieldMerge method. I merged all the cells in the row instead of replacing a row with anther row, achieving the effect I was going for.
Hi Brendan,
if (row != null)
{
// your logic
}
One last thing. How would i add text within that merged cell? I don’t really follow how DocumentBuilder is supposed to work in this scenario. Or would it be better to manipulate the DOM of the document?
Hi Brendan,
foreach (Cell cell in row.Cells)<o:p></o:p>
{<o:p></o:p>
int cellIndex = row.Cells.IndexOf(cell);<o:p></o:p>
// Do something here<o:p></o:p>
}
Hi,
- Your input Word document
- Aspose.Words generated output document showing the undesired behavior
- Your expected document which shows the correct output. Please create this document using Microsoft Word application.
- Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.
Is there a way I can send you this code privately? i’d rather not post it online.
Figured it out:
foreach
(Aspose.Words.Tables.Cell insideCell in insideRow.Cells)<o:p></o:p>
{
if (insideCell.GetText().Contains("REMOVE"))
{
HorizontallyMergeCells(insideRow);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveTo(insideRow.FirstCell.FirstParagraph);
builder.Write("TEST TEXT");
}
}
My problem was that I was inserting the text into insideCell.FirstParagraph, which no longer exists after the merge. I changed this to insideRow.FirstCell.FirstParagraph and it works.
Hi Brendan,