Generate Reports from Excel Data in C#

Generate Reports from Excel Data in C#

You can easily create customized reports from Microsoft Excel data tables. Such reports can be generated programmatically by using Excel spreadsheets as a table of data. This article will be focusing on how to generate reports from Excel data using C#.

The following topics are discussed/covered in this article:

C# API for Generating Reports

I will be using GroupDocs.Assembly for .NET API for generating reports from Excel data. It empowers you to build powerful document automation and report generation applications. The API supports fetching data from various data sources such as XML, JSON, and CSV. You can easily generate reports in all commonly used file formats such as PDF, HTML, and Microsoft Word. It can be used to develop applications in any development environment that targets the .NET platform.

You can either download the DLL of the API or install it using the NuGet.

Install-Package GroupDocs.Assembly

Generate Reports from Excel Data using C#

You can generate reports from Excel data by following the simple steps mentioned below:

  1. Get Excel data source
  2. Define template according to Excel data
  3. Provide data source and template to simple C# code for report generation

Excel Data

The tabular data available in the Excel spreadsheet can be used as a data source to generate reports. I will be using the following sample Excel data for report generation. This is the contract data of clients with their respective managers and agreed contract price.

Excel Data Source
Excel Data Source

Template

Now, define the following template in the DOCX file. This allows iterating Contracts’ data and their respective managers with the contract price. After that, you can jump into code for report generation.

Report Template
Report Template

Convert Excel to Word Report in C#

Please follow the steps mentioned below to automate the conversion of Excel data to the DOCX report based on the template.

The following code sample shows how to generate a report from an Excel data source according to the defined template using C#.

The above code sample will generate the following report.

Generated Report
Generated Report

The DocumentTableOptions class provides a set of options to control the extraction of data from a document table. Here, the FirstRowContainsColumnNames property is set to true.

The DocumentTable class provides access to the data of a single table (or spreadsheet) located in an external document to be used while assembling a document.

The DocumentAssembler class provides methods to generate reports based on the template document with data.

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to generate reports from Excel data using C#. You can learn more about GroupDocs.Assembly for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also