Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 9359154

Browse files
committed
Commit for Excel exporting in server side
1 parent aef8463 commit 9359154

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+201652
-0
lines changed
54.5 KB
Binary file not shown.

Excel-exporting-in-server-side/.vs/TestSample/v15/Server/sqlite3/db.lock

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Excel-exporting-in-server-side/.vs/config/applicationhost.config

Lines changed: 993 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26730.16
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestSample", "TestSample\TestSample.csproj", "{334C8F03-85AB-44BA-9910-A0E8D18157F0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0ED9D229-2BD1-403B-A1A9-EE104F3DF119}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Newtonsoft.Json;
10+
using Syncfusion.EJ2.Base;
11+
using Syncfusion.XlsIO;
12+
using TestSample.Models;
13+
14+
namespace TestSample.Controllers
15+
{
16+
17+
public class HomeController : Controller
18+
{
19+
20+
public IActionResult Index()
21+
{
22+
23+
order = new List<OrdersDetails>();
24+
if (order.Count == 0)
25+
BindDataSource();
26+
ViewBag.dataSource = order.ToArray();
27+
return View();
28+
}
29+
public static List<OrdersDetails> order = new List<OrdersDetails>();
30+
public class ExportModel // Created the model class to Deserialize the GridModel
31+
{
32+
public List<Syncfusion.EJ2.Grids.GridColumns> Columns { get; set; }
33+
public DataManagerRequest Queries { get; set; }
34+
}
35+
36+
public ActionResult ExcelExport(string GridModel)
37+
{
38+
ExportModel exportModel = new ExportModel();
39+
exportModel = (ExportModel)JsonConvert.DeserializeObject(GridModel, typeof(ExportModel)); // Deserialized the GridModel
40+
using (ExcelEngine excelEngine = new ExcelEngine())
41+
{
42+
IApplication application = excelEngine.Excel;
43+
application.DefaultVersion = ExcelVersion.Excel2013;
44+
IWorkbook workbook = application.Workbooks.Create(1);
45+
IWorksheet worksheet = workbook.Worksheets[0];
46+
IEnumerable DataSource = order;
47+
48+
//Import the data to worksheet
49+
IList<OrdersDetails> reports = DataSource.AsQueryable().Cast<OrdersDetails>().ToList();
50+
worksheet.ImportData(reports, 2, 1, true);
51+
MemoryStream stream = new MemoryStream();
52+
workbook.SaveAs(stream);
53+
stream.Position = 0;
54+
55+
//Download the Excel file in the browser
56+
FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel");
57+
58+
fileStreamResult.FileDownloadName = "Output.xlsx";
59+
60+
return fileStreamResult;
61+
}
62+
}
63+
64+
65+
public void BindDataSource()
66+
{
67+
int code = 10000;
68+
for (int i = 1; i < 10; i++)
69+
{
70+
order.Add(new OrdersDetails(code + 1, null, 2.3 * i, "Berlin"));
71+
order.Add(new OrdersDetails(code + 2, "ANATR", 3.3 * i, "Madrid"));
72+
order.Add(new OrdersDetails(code + 3, "ANTON", 4.3 * i, "Cholchester"));
73+
order.Add(new OrdersDetails(code + 4, "BLONP", 5.3 * i, "Marseille"));
74+
order.Add(new OrdersDetails(code + 5, "BOLID", 6.3 * i, "Tsawassen"));
75+
code += 5;
76+
}
77+
}
78+
}
79+
public class OrdersDetails
80+
{
81+
public OrdersDetails()
82+
{
83+
84+
}
85+
public OrdersDetails(long OrderId, string CustomerId, double Freight, string ShipCity)
86+
{
87+
this.OrderID = OrderId;
88+
this.CustomerID = CustomerId;
89+
this.Freight = Freight;
90+
this.ShipCity = ShipCity;
91+
}
92+
public long OrderID { get; set; }
93+
public string CustomerID { get; set; }
94+
public double Freight { get; set; }
95+
public string ShipCity { get; set; }
96+
}
97+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using AngularwithASPCore.Models;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Newtonsoft.Json;
9+
using static TestSample.Controllers.HomeController;
10+
11+
namespace AngularwithASPCore.Controllers
12+
{
13+
[Produces("application/json")]
14+
[Route("api/Orders")]
15+
public class OrdersController : Controller
16+
{
17+
// GET: api/Orders
18+
[HttpGet]
19+
20+
public object Get()
21+
{
22+
var queryString = Request.Query;
23+
24+
int skip = Convert.ToInt32(queryString["$skip"]);
25+
int take = Convert.ToInt32(queryString["$top"]);
26+
var data = OrdersDetails.GetAllRecords().ToList();
27+
return take != 0 ? new { Items = data.Skip(skip).Take(take).ToList(), Count = data.Count() } : new { Items = data, Count = data.Count() };
28+
29+
}
30+
31+
// GET: api/Orders/5
32+
[HttpGet("{id}", Name = "Get")]
33+
public string Get(int id)
34+
{
35+
return "value";
36+
}
37+
38+
// POST: api/Orders
39+
[HttpPost]
40+
public object Post([FromBody]Data dm)
41+
{
42+
var order = OrdersDetails.GetAllRecords();
43+
var Data = order.ToList();
44+
int count = order.Count();
45+
return dm.requiresCounts ? Json(new { result = Data.Skip(dm.skip).Take(dm.take), count = count }) : Json(Data);
46+
}
47+
48+
49+
// PUT: api/Orders/5
50+
[HttpPut]
51+
public object Put(int id, [FromBody]OrdersDetails value)
52+
{
53+
54+
55+
var ord = value;
56+
OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
57+
val.OrderID = ord.OrderID;
58+
val.EmployeeID = ord.EmployeeID;
59+
val.CustomerID = ord.CustomerID;
60+
val.Freight = ord.Freight;
61+
val.OrderDate = ord.OrderDate;
62+
val.ShipCity = ord.ShipCity;
63+
return value;
64+
}
65+
66+
// DELETE: api/ApiWithActions/5
67+
[HttpDelete("{id:int}")]
68+
[Route("Orders/{id:int}")]
69+
public object Delete(int id)
70+
{
71+
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == id).FirstOrDefault());
72+
return Json(id);
73+
}
74+
}
75+
public class Data
76+
{
77+
78+
public bool requiresCounts { get; set; }
79+
public int skip { get; set; }
80+
public int take { get; set; }
81+
}
82+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace AngularwithASPCore.Controllers
8+
{
9+
[Route("api/[controller]")]
10+
public class SampleDataController : Controller
11+
{
12+
private static string[] Summaries = new[]
13+
{
14+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
15+
};
16+
17+
[HttpGet("[action]")]
18+
public IEnumerable<WeatherForecast> WeatherForecasts()
19+
{
20+
var rng = new Random();
21+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
22+
{
23+
DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
24+
TemperatureC = rng.Next(-20, 55),
25+
Summary = Summaries[rng.Next(Summaries.Length)]
26+
});
27+
}
28+
29+
public class WeatherForecast
30+
{
31+
public string DateFormatted { get; set; }
32+
public int TemperatureC { get; set; }
33+
public string Summary { get; set; }
34+
35+
public int TemperatureF
36+
{
37+
get
38+
{
39+
return 32 + (int)(TemperatureC / 0.5556);
40+
}
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)