logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Forgot password?
    • en
    • ru
    • pt
    • es
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Downloading the report as an Excel document in MVC
  • How to create a custom toolbar for web FastReport.NET report

    May 31, 2020

    Many users of report generators are interested in setting up the toolbar when reviewing the

    read more
  • How to create business cards from ASP .Net Core application

    May 31, 2020

    ASP.Net Core Framework is a cross-platform solution for creating web applications. This means that you

    read more
  • How to make a web report authentication

    October 13, 2019

    Every time we generate a web report, ajax request leads to the execution of handlers:

    read more
  • How to create the invoice from ASP.Net Core application

    August 31, 2020

    Few believed in the success of the new open-source ASP.Net Core framework from Microsoft. It’s

    read more
  • How to display report pages on separate sheets in Excel

    October 14, 2019

    Until recently, the export of multi-page reports in Excel format was done on one sheet.

    read more

Downloading the report as an Excel document in MVC

August 13, 2017

Previously, we already examined an example of displaying a printing dialog of a report in HTML and PDF formats. The aim of this article is to show how to save reports in the desired format, providing an example of Excel.

We use the MVC web application.

There is a button, which is provided to save a report. Add it to the web page Home. For this, open the Index.cshtml file in the Views folder.

 

Place the following code in the desired location:

1
2
3
4
5
6
7
 @using (Html.BeginForm("Save", "Home"))
 
 {
 
 <input id="print" type="submit" value="Save report in Excel" />
 
 }

There "Save" - is the name of the handler in the controller. "Home" - is the controller.

Now add the handler "Save" to the Home page controller. For this, open the HomeController.cs file in the Controllers folder:

 

The handler will look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 public void Save()
 
 {
 
 WebReport webReport = new WebReport();
 
 System.Data.DataSet dataSet = new System.Data.DataSet();
 
 dataSet.ReadXml("C://Program Files (x86)//FastReports//FastReport.Net//Demos//Reports//nwind.xml");
 
 webReport.Report.RegisterData(dataSet, "NorthWind");
 
 webReport.Report.Load("C://Program Files (x86)//FastReports//FastReport.Net//Demos//Reports//Simple List.frx");
 
 webReport.ExportExcel2007();
 
 }

Let us take a look at the procedure:

  1. Create an instance of an object of WebReport;
  2. Create an instance of an object of DataSet to work with date;
  3. Load the xml datebase file;
  4. Register the source of the date in the report object;
  5. Load the report template in WebReport object;
  6. Save the report in Excel format.

Now you need to add the handler in the Web.config file, which is located in the root of the project:

1
2
3
4
5
 <handlers>
 
 <add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>
 
 </handlers>

Run the application to see the button: 

 

Click on it. The program will display a dialog to save the report file in xlsx format.

 

After downloading the report, it will be open:

 

Summing up, we can conclude that using the shown application, it is possible to save your report in different formats, available for exporting reports. Using the shown code allows users of the web application to download a report in the desired format without displaying the report itself.

about product download buy
avatar
Dmitriy Fedyashov
Head of QA
.NET FastReport ASP.NET MVC Excel

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Our team
  • Contact us

© 1998-2021 by Fast Reports Inc.

  • Privacy Policy