We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail Merge with Page Break and last cell without border

I have two issues, first I need to add a manual page break into my table (at a place where it makes sense and not just somewhere automatically). Second, all my cells have a bottom line, but the last one should not have one.


I’ve looked at this for the page break and at the forums, but did not find anything usefull:
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-control-new-pages-during-mail-merge.html

I need to be able to control the page break somehow, either with an Mailmerge IF in the document, or via code. I’ve tried to add a PageBreak like this to the table, but nothing happens:

public void MailMerge_MergeField(object sender, MergeFieldEventArgs e)
{
string value = e.FieldValue.ToString();
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToField(e.Field, false);

if (e.DocumentFieldName.StartsWith(“TextType”))
{
builder.InsertBreak(BreakType.PageBreak);
}
}

Second, the buttom border of the cell, if tried this (not specific to the last row yet):

public void MailMerge_MergeField(object sender, MergeFieldEventArgs e)
{
string value = e.FieldValue.ToString();
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToField(e.Field, false);
builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
}

Works for every cell, but the last one :slight_smile:
I’ve attached the document.

Hi,


Thanks for your request.

1. For a page break inside a table you might want to look at this thread.
2. For the second issue can you attach a sample output document and mark with a color the cell you are having problem with?

Best regards,

Hi Remy,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Regarding your second question, I believe I have a solution to your issue.

Try this fix:

// Insert this code in your main function after code merging data with Document object.

dataRowsTotal = DataSet.Tables["Data"].Rows.Count;

DocumentBuilder builder = new DocumentBuilder(document);

// Iterate through all columns and clear bottom and top line style.

for (int colIdx = 0; colIdx < 5; colIdx++){

builder.MoveToCell(1, dataRowsTotal + 1, colIdx, 0);

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;

builder.MoveToCell(1, dataRowsTotal + 2, colIdx, 0);

builder.CellFormat.Borders.Top.LineStyle = LineStyle.None;

}

It will remove the light gray line from the last entry in the table rows and does not require to set up a MergeFieldEventHandler. I believe this is what you wanted to achieve, it should give you the idea.

What was causing the issue is your table has very tiny rows separating the second and second to last rows which was confusing things. Also setting the Row.LineStyle to none for just Bottom was not working, it also required to set the next row’s Top.LineStyle as well.

Thanks,

Thanks, that helped. I’ve implemented it like this:

The currentNode points to the MergeField Start.

Node node = builder.CurrentNode.ParentNode.ParentNode.ParentNode; //Paragraph, Cell, Row

Aspose.Words.Tables.Row row1 = (Aspose.Words.Tables.Row)node;
Aspose.Words.Tables.Row row2 = (Aspose.Words.Tables.Row)row1.NextSibling.NextSibling; //returns the next row

for (int colIdx = 0; colIdx < row1.Cells.Count; colIdx++)
{
//need to do this for the cell above and below
row1.Cells[colIdx].CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
row2.Cells[colIdx].CellFormat.Borders.Top.LineStyle = LineStyle.None;
}

It’s a little more generic and it’s out of the MergeFieldEventHandler again. The table actually continues after the mergefields, therefore this kinda makes it easier.