Can anyone advise me how to create the report in a asp.net core program. I would like to export the report as excel, pdf and word. What is the best way to produce the report in asp.net core? I am looking for advise from expertise
Telerik Reporting Pros are definitely the wide range of supported platforms, the tool can be used in Web and Desktop applications, supporting ASP.NET Core, Blazor, WinForms and WPF to name just a few.
If you use SQL Server, I would recommend using SQL Server Reporting Services (SSRS) for your reporting needs. While I'm not much of a Crystal Reports fan, I would lean towards using SSRS or creating your own report using HTML and then export to PDF or Excel. It would depend on your reporting needs.
I am doing a project in Asp.Net Core 2.1. I used Rotativa.AspNetCore for reporting feature. It is free you can get from the NUGET just install that and thats it.
It Convert the view to pdf. You just pass your model to view and create html table or what you want and along with css. This library convert your view to PDF.
[HttpGet]
public async Task<IActionResult> Registration(int id)
{
var reg = await _context.Registrations
.Include(x => x.Property.Block)
.Include(x => x.Property.Phase)
.Include(x => x.Property.Street)
.Include(x => x.Nomines)
.FirstOrDefaultAsync(x => x.Id == id);
var report = new ViewAsPdf("Registration")
{
PageMargins = { Left = 5, Bottom = 5, Right = 5, Top = 5 },
Model = reg
};
return report;
}
Here is the html for that view. I remove long html stuff but you can check my code.
<div class="row">
<h1 class="report-heading text-center">Registration Form</h1>
<div class="col-xs-9">
<div class="form-group row">
<div class="col-xs-6 no-padding">
<label class="col-xs-3 report-label">Date:-</label>
<label class="col-xs-9 report-field">@(Model.DateTime?.ToString("dd-MMM-yyyy"))</label>
</div>
<div class="col-xs-6 no-padding">
<label class="col-xs-4 report-label">Form #</label>
<label class="col-xs-8 report-field">@(Model.FormNo)</label>
</div>
</div>
<div class="form-group row">
<div class="col-xs-6 no-padding">
<label class="col-xs-5 report-label">Plot/House #</label>
<label class="col-xs-7 report-field">@(Model?.Property?.No)</label>
</div>
<div class="col-xs-6 no-padding">
<label class="col-xs-3 report-label">Street:-</label>
<label class="col-xs-9 report-field">@(Model?.Property?.Street?.Name)</label>
</div>
</div>
<div class="form-group row">
<div class="col-xs-6 no-padding">
<label class="col-xs-3 report-label">Marla:-</label>
<label class="col-xs-9 report-field">@(Model?.Property?.Marla)</label>
</div>
<div class="col-xs-6 no-padding">
<label class="col-xs-3 report-label">Sqft:- </label>
<label class="col-xs-9 report-field">@(Model?.Property?.Sqft)</label>
</div>
</div>
<div class="form-group row">
<div class="col-xs-6 no-padding">
<label class="col-xs-3 report-label">Block:-</label>
<label class="col-xs-9 report-field">@(Model?.Property?.Block?.Name)</label>
</div>
<div class="col-xs-6 no-padding">
<label class="col-xs-3 report-label">Phase:-</label>
<label class="col-xs-9 report-field">@(Model?.Property?.Phase?.Name)</label>
</div>
</div>
</div>
</div>
And i you want to export that view to excel then you just need to add header before returning the view. It is a sample.
public ActionResult Export()
{
Response.AddHeader("Content-Type", "application/vnd.ms-excel");
return View();
}
I hope this will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With