Bullet lists are a common way to display collections of items in documents. GroupDocs.Assembly for Python via .NET makes it easy to generate bulleted lists by iterating over data collections using foreach data bands within list structures.
In your template document (product-bullets.docx), create a bullet list with this structure:
We provide the following products:
• <<foreach [in products]>><<[Name]>> - <<[Description]>>
<</foreach>>
The data band opens inside the bulleted paragraph and closes at the start of the next one, so the band holds the whole list paragraph and each product gets a bullet of its own. After assembly, you’ll get:
We provide the following products:
• Harbor Blend whole bean coffee - Medium roast, roasted weekly
• Aged harbour cheddar - Matured for two years
• Cold-pressed olive oil - First cold pressing
Generate Bullet List from Database Rows
ADO.NET’s DataTable has no Python counterpart. Rows read from a database become a list of dicts, which the template reads the same way. This example reads the products from an SQLite table with Python’s sqlite3 module:
importsqlite3fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssembler# Create a tableconnection=sqlite3.connect(":memory:")connection.row_factory=sqlite3.Rowconnection.execute("CREATE TABLE Products (Name TEXT, Description TEXT)")# Add rowsconnection.executemany("INSERT INTO Products VALUES (?, ?)",[("Harbor Blend whole bean coffee","Medium roast, roasted weekly"),("Aged harbour cheddar","Matured for two years"),("Cold-pressed olive oil","First cold pressing"),])# Each row becomes a dict: its column names are the member names the template readsproducts=[dict(row)forrowinconnection.execute("SELECT Name, Description FROM Products")]connection.close()assembler=DocumentAssembler()assembler.assemble_document("product-bullets.docx","product-bullets-from-database.docx",DataSourceInfo(products,"products"))print("Bullet list generated from database rows successfully.")
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]>>.
Bullet List in Spreadsheet
Bullet lists work in spreadsheet templates too:
fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssemblerproducts=[{"Name":"Harbor Blend whole bean coffee","Description":"Medium roast, roasted weekly"},{"Name":"Aged harbour cheddar","Description":"Matured for two years"},]assembler=DocumentAssembler()assembler.assemble_document("product-bullets.xlsx","product-bullets-report.xlsx",DataSourceInfo(products,"products"))print("Bullet list generated in spreadsheet successfully.")
In the spreadsheet, the data band is a row: its first cell opens the band and its last cell closes it, and the bullet character is part of the cell text:
Product
Description
<<foreach [in products]>>• <<[Name]>>
<<[Description]>><</foreach>>
Bullet List in Email
Generate bullet lists in email messages. This template is an EML file whose plain-text body holds the data band:
fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssemblerproducts=[{"Name":"Harbor Blend whole bean coffee","Description":"Medium roast, roasted weekly"},{"Name":"Aged harbour cheddar","Description":"Matured for two years"},]assembler=DocumentAssembler()assembler.assemble_document("product-bullets.eml","product-bullets-report.eml",DataSourceInfo(products,"products"))print("Bullet list generated in email successfully.")
We provide the following products:
<<foreach [in products]>>• <<[Name]>> - <<[Description]>>
<</foreach>>
Harbor Lane Provisions
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: