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

Free Support Forum - aspose.com

Insert Style Separator to Put Different Paragraph Styles

I would like to insert Style Separator to put different paragraph styles in one paragraph. In the MsWord I can do it by Ctrl+Alt+Enter (see http://www.addbalance.com/usersguide/styles.htm#Style_Separator). But how to do this by Aspose.Words Java API?

Thank you.


Thanks for your inquiry. Please note MS Word has four types of styles - character, paragraph, list and table. You can achieve your requirements by using Paragraph Styles and Character styles as following. It will insert text with different styles in a Paragraph. Hopefully it will help you to accomplish the task.

However, if there is any difference in your requirements and my understanding then please share some more details along with expected document as ZIP file. We will further investigate and will guide you accordingly.

com.aspose.words.Document document = new com.aspose.words.Document();

//Create a character custom Character style
Style charstyle = document.getStyles().add(StyleType.CHARACTER, "MyCharStyle");

DocumentBuilder builder = new DocumentBuilder(document);
//apply Paragraph style - All Heading styles are Paragaph styles.

//Insert some text
builder.write("Heading 1");

//Now we can apply Character style
builder.write("This is text with some other formatting ");


Thank you for your reply. But I have some different requirements. I need to insert the Table Of Content with text “Heading 1” only, i.e. without the text “This is text with some other formatting”, but all text should be placed in one paragraph. Please see attached example Diff_Text_Style_By_Word.zip (13.1 KB) (Please change the extension from .zip to .docx.)

I’ve tried to insert ToC with some modification of your code:

    DocumentBuilder builder = new DocumentBuilder(document);
    // Insert a table of contents at the beginning of the document.
    builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");

but I get the whole text “Heading 1This is text with some other formatting” in ToC.

Thank you again.


Thanks for sharing additional information. After initial investigation, we have logged a new feature request for your requirements WORDSNET-15943 in our issue tracking system. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.


The issues you have found earlier (filed as WORDSNET-15943) have been fixed in this Aspose.Words for .NET 18.2 update and this Aspose.Words for Java 18.2 update.

Please also check the following articles:


Starting from Aspose.Words 18.2, you can insert style separator into the document. The DocumentBuilder.InsertStyleSeparator method allows to apply different paragraph styles to two different parts of a text line.

Please read more detail and code example from the following article.
Inserting Style Separator to Put Different Paragraph Styles