Generate Reports from Excel Data in C#

You can easily create customized reports from Microsoft Excel tables. This article shows how to generate reports from Excel data using C#.

The following topics are covered:

C# API for Generating Reports

I use the GroupDocs.Assembly for .NET API to generate reports from Excel data. It lets you build document automation and report generation apps. The API reads data from XML, JSON, CSV, and Excel, and creates PDFs, HTML, or Word files. It works in any .NET development environment.

You can either download the DLL or install it via NuGet.

Install-Package GroupDocs.Assembly

Generate Reports from Excel Data using C#

Follow these steps to create a report:

  1. Get Excel data source.
  2. Define a template that matches the Excel data.
  3. Use the C# code for report generation.

Excel Data

The Excel spreadsheet provides the tabular data for the report. Below is a sample file that contains client contracts, managers, and contract prices.

Excel Data Source

Excel Data Source

Template

Create a DOCX template that iterates over the contract rows and inserts manager names and prices. This template will be used by the code to generate the final report.

Report Template

Report Template

Convert Excel to Word Report in C#

Follow these actions to automate the conversion:

The code below demonstrates how to generate a report from an Excel source using C#.

The code produces a report like this:

Generated Report

Generated Report

The DocumentTableOptions class lets you control how data is read from a table. In this example, the FirstRowContainsColumnNames property is set to true.

The DocumentTable class gives access to a single table (or spreadsheet) from an external document for use during assembly.

The DocumentAssembler class contains methods that merge the template with the data to create the final report.

Get a Free License

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

Conclusion

This article showed how to generate reports from Excel data using C#. For more details, see the GroupDocs.Assembly for .NET documentation. If you have questions, visit the forum.

See Also