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.
Generate Reports from Excel Data using C#
You can generate reports from Excel data by following the simple steps mentioned below:
- Get Excel data source
- Define template according to Excel data
- Provide data source and template to simple C# code for report generation
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.
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.
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.
- Define Excel data file, the template file, and DOCX output report file paths
- Define DocumentTableOptions
- Create DocumentTable with defined Excel data file and DocumentTableOptions
- Call the AssembleDocument method of the DocumentAssembler class to generate the report from the provided Excel data and defined 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.
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.
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.