Loss of Paragraph Formating

Hi,

I’m losing my paragraph settings b/t two tables. I want to have a certain distance b/t two tables. Here is my example:

// end of table 1
builder.ParagraphFormat.SpaceBefore = 0;
builder.ParagraphFormat.SpaceAfter = 0;
builder.Font.Size = 5;
builder.Writeln(" ");
// builder.InsertParagraph(); // tried this or the above line
builder.RowFormat.ClearFormatting();
builder.CellFormat.ClearFormatting();
builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Font.Bold = false;
builder.Font.Size = 11;

PageSetup pageSetup = builder.CurrentSection.PageSetup;
int tableWidth = (int)(pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin);
builder.CellFormat.Width = (tableWidth / 10) * 2;
builder.CellFormat.Width = (tableWidth / 4);
builder.StartTable(); // Table 2 start

The paragraph spacing I have inb/t the tables is set correctly for before, but the after is set to auto. Go figure? Any ideas? I’m using version 4.0.2

Thanks.

Dear Rob,

Thank you for your question.

You have lost paragraph formatting due to running builder.ParagraphFormat.ClearFormatting() method which clears formatting of current paragraph. In your case a current paragraph is the paragraph between tables. To prevent this you should initially insert cell into the second table and then run paragraph cleaning method.

Look at my code sample below that produced output document with correct setting for paragraph between tables. Output file is attached.

builder.StartTable();
// Insert a cell
builder.InsertCell();
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.CellFormat.Borders.LineStyle = LineStyle.Triple;
builder.Write("This is row 1 cell 1");
// Insert a cell
builder.InsertCell();
builder.Write("This is row 1 cell 2");
builder.EndRow();
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 1");
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 2");
builder.EndRow();
builder.EndTable();
// end of table 1
builder.ParagraphFormat.SpaceBefore = 0;
builder.ParagraphFormat.SpaceAfter = 0;
builder.Font.Size = 5;
builder.Writeln("some text to check between tables para formatting ");
// builder.InsertParagraph(); // tried this or the above line
PageSetup pageSetup = builder.CurrentSection.PageSetup;
int tableWidth = (int)(pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin);
builder.StartTable(); // Table 2 start
builder.RowFormat.ClearFormatting();
builder.CellFormat.ClearFormatting();
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = (tableWidth / 10) * 2;
builder.CellFormat.Width = (tableWidth / 4);
builder.InsertCell();
builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Font.Bold = false;
builder.Font.Size = 11;
builder.Writeln("some text to check cell para formatting");
doc.Save(MyDir + "out.docx");

If you have any concerns please ask us.