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

Free Support Forum - aspose.com

Inserts Style Separator in End of Cell Paragraph of Table in Word document using C# .NET | Insert Break or new Para

Hi,
It seems DocumentBuilder.InsertStyleSeparator doesn`t work when current paragraph located into the table
StyleSeparator.zip (16.8 KB)

@dmbk,

We have logged this issue in our bug tracking system with ID WORDSNET-20900. Your forum thread has been linked to this issue and you will be notified here as soon as it will get resolved. Sorry for the inconvenience.

@dmbk,

Regarding WORDSNET-20900, this turns out to be an expected behavior. MS Word also does nothing when cursor is positioned in the last Paragraph of the Cell or at the end of the last Paragraph of the last Section which is positioned inside Content Control. So, to create Paragraphs with different styles it is possible to use DocumentBuilder.InsertBreak(BreakType.ParagraphBreak) instead of DocumentBuilder.InsertStyleSeparator(). Sample code is as follows:

var doc = new Document();
var docBuilder = new DocumentBuilder(doc);
var table = docBuilder.StartTable();
docBuilder.InsertCell();
docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
docBuilder.Write("Normal Style ");

docBuilder.Font.Hidden = true;
//docBuilder.InsertStyleSeparator();
docBuilder.InsertBreak(BreakType.ParagraphBreak);
docBuilder.Font.Hidden = false;

docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Quote;
docBuilder.Write("Quote Style");
docBuilder.EndTable();
docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
docBuilder.Write("Normal Style ");
docBuilder.InsertStyleSeparator();
docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Quote;
docBuilder.Write("Quote Style");
doc.Save("C:\\Temp\\20.8.docx");

@dmbk,

You can also use the following code to fix this problem:

var doc = new Document();
var docBuilder = new DocumentBuilder(doc);
var table = docBuilder.StartTable();

// Suggested changes
Cell cell = docBuilder.InsertCell();
docBuilder.InsertParagraph();
docBuilder.MoveTo(cell.FirstParagraph);

docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
docBuilder.Write("Normal Style ");
docBuilder.InsertStyleSeparator();
docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Quote;
docBuilder.Write("Quote Style");
docBuilder.EndTable();
docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
docBuilder.Write("Normal Style ");
docBuilder.InsertStyleSeparator();
docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Quote;
docBuilder.Write("Quote Style");

doc.Save("C:\\Temp\\20.8.docx"); 

Inserting style separator is slightly tricky i.e. InsertStyleSeparator() method does not insert anything but instead it modifies current Paragraph’s properties and convert it into style separator Paragraph. This is the way similar to what MS Word does. For Table content, we cannot convert end of Cell Paragraph, that is why we need to insert new Paragraph first.

@awais.hafeez Thanks for the clarification.