Generate report from a template in Go (Golang)

Generate report from a template in Go (Golang)

Generate professional print-ready DOCX, DOC, RTF, PDF reports in Go easily with Aspose Reporting Engine. Generate documents and reports based on templates, automate your document-processing systems with Go SDK.


It is believed that an application is only as good as the data we can get out of it, that`s why Report Generation has become an essential part of modern software design. In general terms Report Generation is a process that takes required data from some informational environment and exports it to standard document formats such as DOCX, DOC, RTF or PDF. Report generation consists of making a document template with a special placeholder tags that, in the final document, are replaced by data from external data sources.

Reporting Engine

Cloud Reporting Engine is a subset of Aspose Words REST API that allows Go developers to generate reports with an extended set of reporting features. It acts as the middleware between the data layer and the application layer. The most powerful feature of the Reporting Engine is the LINQ-scripting, used to bind placeholder tags in the report template to the external JSON, XML or CSV data sources and perform data sorting, filtering and grouping on the fly. This approach makes the template syntax plain, flexible and effective.

Since Report Generation is a logged-in service, you need to have an Client Id and Client Secret identifiers to authenticate before being able to use the Aspose Cloud API.

Automate your document-processing systems with Go SDK

Aspose provides the best document-processing capabilities with constantly emerging Cloud SDK family, targeting mainstream programming languages, and allows developers to:

  • Generate DOCX, DOC, PDF reports in a fast, clear and reliable way.
  • Automate the report generation process and standardize the results with a consistent style that looks appealing and cool.
  • Design data visualizations to deliver the best analytical behavior to the end-user and meet his personalized needs.

Using our Go SDK you can easily integrate with Cloud Reporting Engine API and generate highly customized reports. Richly formatted documents like packing slips, inventories, invoices, shipment reports can be constructed on the fly as a part of your application.

Report Generation Input and Output

The inputs to the Report Generation process are:

  • The underlying data. A good report generation practice requires data, that is exact, timely, appropriate for the effective supervision and decisions at hand.
  • The report template, containing static content (text, images, logos, etc.) and special tags with composing LINQ-expressions, that regulate the report generation.

The output can be rendered in a variety of document formats: DOCX, DOC, PDF, RTF, HTML, MHTML, TXT and many others.

Generate Your Report with Go in 3 Steps

  • Prepare your source data in JSON, XML or CSV formats.
  • Create a report template.
  • Write a simple Go application to bind the data to the template and produce the output document.

Preparing a Source Data

Prepare your data by extracting and transforming your business objects and other data sources to JSON, XML and CSV. Since data is often fragmented and distributed in a variety of formats, creating the appropriate information processing subsystem may be required.

Creating a Template

Create a template, containing static content and special tags with composing LINQ-expressions.

A good Report design should reflect the end-user`s view and the types of questions the user will ask. The type of the data content is the first reason to decide what type of report template you may use. For many decision-makers, diagrams and charts can provide additional insight into certain tendencies that may not be obvious from tabular reports. Therefore, tabular data and graphics can be combined in a single report with the relative weighting determined by end-user preferences and analytical requirements.

Writing a simple Go code to generate a report

Writing a Go code is the final step: Cloud Reporting Engine will interpret and apply the composing LINQ-expressions, merging template and data.

How to generate a report in Go

  1. Install the latest version of Go library.
  2. Go to the Aspose Cloud Dashboard.
  3. Create a new Account to access all applications and services or Sign In to your account.
  4. Click on Applications in the left menu to get Client Id and Client Secret.
  5. Check out the Developer Guide to working with Reports in Go.
  6. Check out our GitHub repository for a complete API list along with working examples.
  7. Check out the API Reference page for the description of APIs parameters.

How to make a report generation in Go

Json Data
  "client": "Mr.Brown",
  "address": "St.Road 82",
  "orders": [
      "date": "2015-03-05",
      "products": [
        { "name": "Monitor", "price": 2, "quantity": 2},
        { "name": "Computer", "price": 3, "quantity": 1}
      "date": "2015-03-15",
      "products": [
        { "name": "Monitor", "price": 2, "quantity": 1},
        { "name": "Printer", "price": 1, "quantity": 2},
	{ "name": "Computer", "price": 3, "quantity": 1}
DOCX Template
Code Sample Go
config, _ := models.NewConfiguration("config.json")
wordsApi, ctx, _ := api.CreateWordsApi(config)

template, _ := os.Open("template.docx")
data, _ := ioutil.ReadFile("data.json")
settings := models.ReportEngineSettings{ DataSourceType: "Json" }
response, _ := wordsApi.BuildReportOnline(ctx, template, string(data), settings, nil)
defer response.Body.Close()

output, _ := os.Create("result.docx")
defer output.Close()
io.Copy(output, response.Body)
	"AppKey": "##################",
	"AppSid": "####-####-####-####-####"


Support and Learning Resources