Can we set custom list properties as default properties. in doc

Can we set custom list properties as default properties in doc?

Hi
Thanks for your request. Could you please describe the main goal you need to reach? If you need to change appearance of lists in the document, you can change list’s definitions in Document.Lists collections. This collection contains all lists definitions available in the document.
Best regards,

in a aspose genrated document i set some list properties.
e.g.

list.getListLevels().get(0).getFont().setBold(true);
list.getListLevels().get(0).getFont().setSize(14);
list.getListLevels().get(0).getFont().setColor(Color.BLACK);
list.getListLevels().get(0).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(0).setTabPosition(0);
list.getListLevels().get(0).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(0).setNumberFormat("\u0000)");

list.getListLevels().get(1).getFont().setBold(true);
list.getListLevels().get(1).getFont().setSize(12);
list.getListLevels().get(1).getFont().setColor(Color.BLACK);
list.getListLevels().get(1).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(1).setTabPosition(0);
list.getListLevels().get(1).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(1).setNumberFormat("\u0000.\u0001)");

list.getListLevels().get(2).getFont().setBold(false);
list.getListLevels().get(2).getFont().setSize(12);
list.getListLevels().get(2).getFont().setColor(Color.BLACK);
list.getListLevels().get(2).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(2).setNumberStyle(NumberStyle.ARABIC);
// list.getListLevels().get(2).setNumberFormat("\u0000.\u0001.\u0002)");
list.getListLevels().get(2).setNumberFormat("");

listStyleLevel1.getListFormat().setList(list);

then i while editing the genrated document when i am adding some data in the list the WORD again takes the default formatting for the user entered data.

SO HOW CAN I SET THESE MY DEFINED PROPERTIES OF LIST AS DEFAULT FOR THE DOCUMENT.
SO THAT ANY DATA ENTERED IN THE LIST WILL BE OF THE SAME FORMATTING.

Hi
Thanks you for additional information. Actually, when you create a Document from scratch the document does not contain any lists. Definition of lists (or correctly list templates) are defined in the template attached to the documents. These definitions you see in the menu in MS Word.
Also, if you created a list in the document and need to add one more item into it, the new added item should inherit formatting of the list. I created a short video that demonstrated this.
Best regards,

Hi,

Thanks. But in my case it is not taking the list formatting that i am taking. i am attaching the doc which i am genrating and making the changes it.

Hi
Thank you for additional information. Most likely, some of paragraph formatting is not defined in the style, but directly in the paragraph. That is why formatting is different. Could you please show me full code you are using to generate this document? I will check it and provide you more information.
Best regards,

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a style with a list asociated with it.
Style listStyleLevel1 = doc.getStyles().add(StyleType.PARAGRAPH, "listStyleLevel1");

// asociate a list with style.
com.aspose.words.List list = doc.getLists().add(ListTemplate.NUMBER_ARABIC_DOT);

list.getListLevels().get(0).getFont().setBold(true);
list.getListLevels().get(0).getFont().setSize(14);
list.getListLevels().get(0).getFont().setColor(Color.BLACK);
list.getListLevels().get(0).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(0).setTabPosition(0);
list.getListLevels().get(0).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(0).setNumberFormat("\u0000)");

list.getListLevels().get(1).getFont().setBold(true);
list.getListLevels().get(1).getFont().setSize(12);
list.getListLevels().get(1).getFont().setColor(Color.BLACK);
list.getListLevels().get(1).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(1).setTabPosition(0);
list.getListLevels().get(1).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(1).setNumberFormat("\u0000.\u0001)");

list.getListLevels().get(2).getFont().setBold(false);
list.getListLevels().get(2).getFont().setSize(12);
list.getListLevels().get(2).getFont().setColor(Color.BLACK);
list.getListLevels().get(2).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(2).setNumberStyle(NumberStyle.ARABIC);
// list.getListLevels().get(2).setNumberFormat("\u0000.\u0001.\u0002)");
list.getListLevels().get(2).setNumberFormat("");

listStyleLevel1.getListFormat().setList(list);

for (int i = 0; i <3; i++)
{
    builder.getParagraphFormat().setStyle(listStyleLevel1);
    builder.getFont().setSize(14);
    builder.getFont().setBold(true);
    builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
    builder.getParagraphFormat().setLeftIndent(0);
    builder.writeln("Section");
    builder.getFont().clearFormatting();
    builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);

    builder.getListFormat().listIndent();
    for (int j = 0; j <3; j++)
    {
        builder.getParagraphFormat().setStyle(listStyleLevel1);
        builder.getFont().setSize(12);
        builder.getFont().setBold(true);
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
        builder.getParagraphFormat().setLeftIndent(0);
        builder.getParagraphFormat().getTabStops().add(new TabStop(5));
        builder.writeln("Clause Title");
        builder.getFont().clearFormatting();
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);

        builder.getListFormat().listIndent();
        for (int k = 0; k <2; k++)
        {
            builder.getParagraphFormat().setStyle(listStyleLevel1);
            builder.getFont().setSize(12);
            builder.getFont().setBold(false);
            builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
            builder.getParagraphFormat().setLeftIndent(0);
            builder.writeln("Clause Text");
            builder.getFont().clearFormatting();
            builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
        }
        builder.getListFormat().listOutdent();
    }
    builder.getListFormat().listOutdent();
}
builder.getParagraphFormat().clearFormatting();
doc.save("C:/Kumar/Test2.doc");

Hi
Thank you for additional information. I modified your code and now it works as expected:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a style with a list asociated with it.
Style listStyleLevel1 = doc.getStyles().add(StyleType.PARAGRAPH, "listStyleLevel1");
Style listStyleLevel2 = doc.getStyles().add(StyleType.PARAGRAPH, "listStyleLevel2");
Style listStyleLevel3 = doc.getStyles().add(StyleType.PARAGRAPH, "listStyleLevel3");
// asociate a list with style.
com.aspose.words.List list = doc.getLists().add(ListTemplate.NUMBER_ARABIC_DOT);
list.getListLevels().get(0).getFont().setBold(true);
list.getListLevels().get(0).getFont().setSize(14);
list.getListLevels().get(0).getFont().setColor(Color.BLACK);
list.getListLevels().get(0).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(0).setTabPosition(0);
list.getListLevels().get(0).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(0).setNumberFormat("\u0000)");
list.getListLevels().get(0).setLinkedStyle(listStyleLevel1);
list.getListLevels().get(1).getFont().setBold(true);
list.getListLevels().get(1).getFont().setSize(12);
list.getListLevels().get(1).getFont().setColor(Color.BLACK);
list.getListLevels().get(1).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(1).setTabPosition(5);
list.getListLevels().get(1).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(1).setNumberFormat("\u0000.\u0001)");
list.getListLevels().get(1).setLinkedStyle(listStyleLevel2);
list.getListLevels().get(2).getFont().setBold(false);
list.getListLevels().get(2).getFont().setSize(12);
list.getListLevels().get(2).getFont().setColor(Color.BLACK);
list.getListLevels().get(2).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(2).setTabPosition(10);
list.getListLevels().get(2).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(2).setNumberFormat("");
list.getListLevels().get(2).setLinkedStyle(listStyleLevel3);
// Configure styles
listStyleLevel1.getListFormat().setList(list);
listStyleLevel1.getListFormat().setListLevelNumber(0);
listStyleLevel1.getFont().setSize(14);
listStyleLevel1.getFont().setBold(true);
listStyleLevel1.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
listStyleLevel1.getParagraphFormat().setLeftIndent(0);
listStyleLevel2.getListFormat().setList(list);
listStyleLevel2.getListFormat().setListLevelNumber(1);
listStyleLevel2.getFont().setSize(12);
listStyleLevel2.getFont().setBold(true);
listStyleLevel2.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
listStyleLevel2.getParagraphFormat().setLeftIndent(0);
listStyleLevel3.getListFormat().setList(list);
listStyleLevel3.getListFormat().setListLevelNumber(2);
listStyleLevel3.getFont().setSize(12);
listStyleLevel3.getFont().setBold(false);
listStyleLevel3.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
listStyleLevel3.getParagraphFormat().setLeftIndent(0);
for (int i = 0; i <3; i++)
{
    builder.getParagraphFormat().setStyle(listStyleLevel1);
    builder.writeln("Section");
    builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
    for (int j = 0; j <3; j++)
    {
        builder.getParagraphFormat().setStyle(listStyleLevel2);
        builder.writeln("Clause Title");
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
        for (int k = 0; k <2; k++)
        {
            builder.getParagraphFormat().setStyle(listStyleLevel3);
            builder.writeln("Clause Text");
            builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
        }
    }
}
doc.save("C:\\Temp\\out.doc");

I created a separate style for each list level. Set linked style for each list level. And defined all formatting in the styles.
Hope this helps.
Best regards,

Hi, alex

i had applied the changes tu suggested in my project. i had made some modifications to the same prog u gave.

Style listStyleLevel1 = doc.getStyles().add(StyleType.PARAGRAPH, "listStyleLevel1");
// Style listStyleLevel2 = doc.getStyles().add(StyleType.PARAGRAPH, "listStyleLevel2");
// Style listStyleLevel3 = doc.getStyles().add(StyleType.PARAGRAPH, "listStyleLevel3");

// asociate a list with style.
com.aspose.words.List list = doc.getLists().add(ListTemplate.NUMBER_ARABIC_DOT);

list.getListLevels().get(0).getFont().setBold(true);
list.getListLevels().get(0).getFont().setSize(14);
list.getListLevels().get(0).getFont().setColor(Color.BLACK);
list.getListLevels().get(0).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(0).setNumberPosition(0);
list.getListLevels().get(0).setTabPosition(0);
list.getListLevels().get(0).setTextPosition(0);
list.getListLevels().get(0).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(0).setNumberFormat("\u0000)");
// list.getListLevels().get(0).setLinkedStyle(listStyleLevel1);

list.getListLevels().get(1).getFont().setBold(true);
list.getListLevels().get(1).getFont().setSize(12);
list.getListLevels().get(1).getFont().setColor(Color.BLACK);
list.getListLevels().get(1).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(1).setNumberPosition(0);
list.getListLevels().get(1).setTabPosition(0);
list.getListLevels().get(1).setTextPosition(0);
list.getListLevels().get(1).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(1).setNumberFormat("\u0000.\u0001)");
// list.getListLevels().get(1).setLinkedStyle(listStyleLevel2);

list.getListLevels().get(2).getFont().setBold(false);
list.getListLevels().get(2).getFont().setSize(12);
list.getListLevels().get(2).getFont().setColor(Color.BLACK);
list.getListLevels().get(2).setAlignment(ListLevelAlignment.LEFT);
list.getListLevels().get(2).setNumberPosition(0);
list.getListLevels().get(2).setTabPosition(0);
list.getListLevels().get(2).setTextPosition(0);
list.getListLevels().get(2).setNumberStyle(NumberStyle.ARABIC);
list.getListLevels().get(2).setNumberFormat("");
// list.getListLevels().get(2).setLinkedStyle(listStyleLevel3);

but after making these changes in the doc creation i found a issue that the list numbering has the issue. i have attached the document. for your reference.

the document i an creating is being created in different parts. and then mearged.

can u help me on this.

Hi, alex

i would like to add one moew thing to this.

that in the creation process i have 2 documents old and new. i check it node by node and then compare and then add or subract the nodes. from the doc.

i am doing this by

public static void insertDocument(Node insertAfterNode, Node insertNode) throws Exception
{
    // Make sure that the node is either a paragraph or table.
    if (insertAfterNode.getNodeType() != NodeType.PARAGRAPH &&
        insertAfterNode.getNodeType() != NodeType.TABLE)
    {
        throw new Exception("The destination node should be either a paragraph or table.");
    }

    // We will be inserting into the parent of the destination paragraph.
    CompositeNode dstStory = insertAfterNode.getParentNode();

    // This object will be translating styles and lists during the import.
    NodeImporter importer = new NodeImporter(insertNode.getDocument(), insertAfterNode.getDocument(),
        ImportFormatMode.USE_DESTINATION_STYLES);

    Node newNode = importer.importNode(insertNode, true);

    dstStory.insertAfter(newNode, insertAfterNode);
}

this is where the numbering of the document gets messed up.

Hi
Thanks for your request. The problem occurs because you are creating a separate NodeImporter for each node. If you need to preserve numbering of the source document, you should use a single instance of NodeImporter class to import all nodes from the source document.
Best regards,

hi alex,

Is there any other way of doing it, as i need to pass document to the NodeImporter. As you might have noticed that i am getting a document from the node that i am passing to the function.

I am ittrating through a collection of nodes and baised on a conditions i am inserting it.

If as per your reply i pass the orignal document to the NodeImporter then how shall i mention where to insert the node in document.

Regards,

Kumar Sabnis

Hi Kumar,

Thanks for your request. Since you apply formatting through styles, you can define you can define the same styles in the destination document and import paragraphs from the source document with UseDestinationStyles option. In this case, style from the destination document will be applied and numbering should be retained.
Could you please also describe your goal in more details? Maybe we will managed to find other way to achieve what you need.
Best regards,