Bullet lists are a common way to display collections of items in documents. GroupDocs.Assembly for .NET makes it easy to generate bulleted lists by iterating over data collections using foreach data bands within list structures.
In your template document (BulletListTemplate.docx), create a bullet list with this structure:
We provide the following products:
<<foreach [in products]>>
• <<[Name]>> - <<[Description]>>
<</foreach>>
After assembly, you’ll get:
We provide the following products:
• Laptop - High-performance laptop
• Mouse - Wireless mouse
• Keyboard - Mechanical keyboard
Generate Bullet List from DataTable
You can also generate bullet lists from ADO.NET DataTable:
usingGroupDocs.Assembly;usingSystem.Data;publicstaticvoidGenerateBulletListFromDataTable(){// Create DataTableDataTableproductsTable=newDataTable("Products");productsTable.Columns.Add("Name",typeof(string));productsTable.Columns.Add("Description",typeof(string));// Add rowsproductsTable.Rows.Add("Laptop","High-performance laptop");productsTable.Rows.Add("Mouse","Wireless mouse");productsTable.Rows.Add("Keyboard","Mechanical keyboard");DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("BulletListTemplate.docx","BulletListOutput.docx",newDataSourceInfo(productsTable,"products"));Console.WriteLine("Bullet list generated from DataTable successfully.");}
Simple Bullet List (Name Only)
For simple lists showing only names:
usingGroupDocs.Assembly;usingSystem.Collections.Generic;publicstaticvoidGenerateSimpleBulletList(){List<string>items=newList<string>{"Item 1","Item 2","Item 3"};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("SimpleBulletListTemplate.docx","SimpleBulletListOutput.docx",newDataSourceInfo(items,"items"));Console.WriteLine("Simple bullet list generated successfully.");}
Template for simple list:
Items:
<<foreach [item in items]>>• <<[item]>>
<</foreach>>
A string has no members to name, so the data band names its iteration variable (item) and outputs the item itself with <<[item]>>. The _Text suffix applies only to arrays of simple values in JSON and XML data.
Bullet List in Spreadsheet
Bullet lists work in spreadsheet templates too:
usingGroupDocs.Assembly;usingSystem.Collections.Generic;publicstaticvoidGenerateBulletListInSpreadsheet(){List<Product>products=newList<Product>{newProduct{Name="Laptop",Description="High-performance laptop"},newProduct{Name="Mouse",Description="Wireless mouse"}};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("BulletListTemplate.xlsx","BulletListOutput.xlsx",newDataSourceInfo(products,"products"));Console.WriteLine("Bullet list generated in spreadsheet successfully.");}
Bullet List in Email
Generate bullet lists in email messages:
usingGroupDocs.Assembly;usingSystem.Collections.Generic;publicstaticvoidGenerateBulletListInEmail(){List<Product>products=newList<Product>{newProduct{Name="Laptop",Description="High-performance laptop"},newProduct{Name="Mouse",Description="Wireless mouse"}};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("BulletListTemplate.msg","BulletListOutput.msg",newDataSourceInfo(products,"products"));Console.WriteLine("Bullet list generated in email successfully.");}
Warning
In Word documents, ensure the bullet list formatting is applied in the template. The foreach data band will repeat the list item format for each collection element.
Advanced Usage Topics
To learn more about nested bullet lists, conditional list items, and advanced list formatting, please refer to the advanced usage section.
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: