How to create bulleted and numbered lists using DocumentBuilder

This feature is available in Aspose.Word 1.5.2. Examples will be added to the documentation later.

this.doc = TestUtil.Open(“Blank.doc”);
this.builder = new DocumentBuilder(doc);

builder.Writeln(“List heading paragraph.”);
//This starts a bulleted list.
builder.ListFormat.ApplyBulletDefault();
builder.Writeln(“List item 1.”);
builder.Writeln(“List item 2.”);
//Switches to second level in the list.
builder.ListFormat.ListIndent();
builder.Writeln(“List item 1.1”);
//Returns to the first level.
builder.ListFormat.ListOutdent();
builder.Writeln(“List item 3.”);
//Stop the bulleted list.
builder.ListFormat.RemoveNumbers();
builder.Writeln(“Normal text.”);
this.doc = TestUtil.SaveOpen(doc, “TestDocBuilderListBulleted Out.doc”);


To create a numbered list, use the ListFormat.ApplyNumberDefault() method.

I’m building a large document that has multiple regions defined. All of the regions are populated with a dataset. So to create bullets I need to define them inside of a datatable cell. Is there any way to do this?

Thanks,

Martin

This question should be on a different topic but I don’t seem to be able to move it.

You are asking “How to create bulleted and numbered lists using mail merge regions”.

If you want to create a bulleted list from a data table then merge regions is a good way to go. All you need to do is to create one bulleted list item in the document and properly enclose it in the merge region and the list will grow when populated from the table.

I’ll try to express this in plain text:


  • TableStart:MyTableTableEnd:MyTable




    Basically, create one paragraph in your document, insert TableStart, TableEnd and data field(s) all into the same paragraph and make the paragraph bulleted. Now you have a mail merge region that will form a bulleted list when grows.

  • After reading my post again I didn’t ask the question properly.

    That would definitely work if I could have regions inside of regions. What I am doing is building a list of topics and sub topics. There is a single table for each topic. The topic text is in one column and a bulleted list of sub topics is in another column.

    So what I do is build a datatable that includes a topic in the first column and all of the sub topics in another column. And each topic has its own row.

    Does this explain it a little better? Any ideas that you have would be greatly appreciated.

    Cheers,

    Martin

    You are right, nested merge regions are not yet supported and that would be the most natural solution for your topic - subtopic scenario.

    Basically, if you cannot build your document using mail merge features because of this limitation, you still can use DocumentBuilder class. It just means you will be able to use less of MS Word to visually design your report and need to use a bit more programmatic effort to build your document, but it is certainly possible to build document of any complexity using DocumentBuilder.

    As an extreme example, you can build entire report from empty document using DocumentBuilder. You can insert report title, create tables for topics and subtopics, create lists, specify font and paragraph formatting, basically anything. You will just enumerate through rows of your tables and invoke DocumentBuilder methods to build the content. This is a bit more programming than just using mail merge, but still can be done easily.

    You can also try to combine using DocumentBuilder with mail merge and an interesting technique of copying sections of the document.

    An example of combining mail merge with DocumentBuilder is that you use mail merge to build outer topics only and provide MailMerge.MergeField event handlers. Inside the handlers you invoke DocumentBuilder to create subtopic content.

    Copying sections seems as a good technique and used by many customers. You can potentially separate your topic/subtopic table into a separate section inside the document using section breaks that do not start a new page. Then you can use Document.Sections collection to copy that section as many times as number of records you have in your data source. Then you can navigate to any cell in any table using DocumentBuilder.MoveToCell method to insert content of subtopics.

    These are just general directions. Let us know if you need more detailed suggestions.




    Thank you for your reply Romank

    I like the idea of using MailMerge.MergeField event handlers. And then inside of the handlers using the DocumentBuilder to create the subtopic content. Do you have any examples of this?

    Thanks,

    Martin

    It will be something like this https://forum.aspose.com/t/130472.

    The key in this example is to use DocumentBuilder.MoveToMergeField while inside a MergeField handler. Once done that you can use other DocumentBuilder methods to insert content, tables, specify formatting etc.

    You might also wish to look at Aspose.Consulting.

    I actually figured this one out on my own before seeing your reply. Thanks for the info anyways. I’m definitely feeling more comfortable with your software now.

    Cheers,

    Martin

    The issues you have found earlier (filed as 39) have been fixed in this update.


    This message was posted using Notification2Forum from Downloads module by aspose.notifier.
    (24)