A “Hello, World!” example is often the first step when exploring GroupDocs.Assembly for Python via .NET. It serves as a simple test to confirm that your development environment is correctly set up and that the library is functioning as expected.
Overview
GroupDocs.Assembly for Python via .NET builds reports from templates. A template is an ordinary document, here a Word document, with tags such as <<[customer.Name]>> where the data goes. The data can be Python dicts and lists, JSON, XML or CSV files, or the tables of other documents, and the report can be saved in any of the supported formats.
How to build a report from a template
The following steps demonstrate how to fill a template with data using GroupDocs.Assembly for Python via .NET:
Import the DocumentAssembler and DataSourceInfo classes from groupdocs.assembly.
Put the data in a Python dict. Its keys are the names the template’s tags read.
Wrap the dict in a DataSourceInfo with the name the template uses for it, customer.
Call assemble_document() with the template, the report to write and the data.
The template, hello-world.docx, holds:
Hello, <<[customer.Name]>>!
Your order of <<[customer.Product]>> is on its way.
Harbor Lane Provisions, 18 Quayside Road, Port Ellery
Complete example
The example below fills the template with the data of one customer and saves the report as hello-world-report.docx:
fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssemblerdefhello_world():# The data: a dict whose keys the template's tags readcustomer={"Name":"Quayside Bistro","Product":"Harbor Blend whole bean coffee"}# Fill the template's tags and save the reportassembler=DocumentAssembler()assembler.assemble_document("hello-world.docx","hello-world-report.docx",DataSourceInfo(customer,"customer"))print("The report is saved to hello-world-report.docx")if__name__=="__main__":hello_world()
The following sample file is used in this example: hello-world.docx
The report reads “Hello, Quayside Bistro!” and “Your order of Harbor Blend whole bean coffee is on its way.”: each tag is replaced with the value of its key, and the rest of the document, its text and formatting, stays as it is.
The output format follows the report’s extension: name it hello-world-report.pdf and the same template gives a PDF. To fill tables, lists and charts from lists of dicts, see the Quick Start Guide and the Developer Guide.
Additional resources
This demo references the GroupDocs.Assembly for Python via .NET code samples.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.