Skip to content

Commit fbb2cb0

Browse files
authored
Merge pull request #191 from SyncfusionExamples/858102-CREExcelElasticBeanStalkExample
858102-Prepare UG to create, read and edit an Excel file in Elastic Bean Stalk using XlsIO
2 parents 6477656 + a77600e commit fbb2cb0

File tree

156 files changed

+149841
-0
lines changed

Some content is hidden

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

156 files changed

+149841
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create Excel", "Create Excel\Create Excel.csproj", "{8CD8EE61-8C2D-4E7F-897B-13FD051C9B32}"
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+
{8CD8EE61-8C2D-4E7F-897B-13FD051C9B32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8CD8EE61-8C2D-4E7F-897B-13FD051C9B32}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8CD8EE61-8C2D-4E7F-897B-13FD051C9B32}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8CD8EE61-8C2D-4E7F-897B-13FD051C9B32}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
using System.Diagnostics;
2+
using Create_Excel.Models;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Syncfusion.XlsIO;
5+
using static Syncfusion.XlsIO.Parser.Biff_Records.Charts.ChartPicfRecord;
6+
using Syncfusion.XlsIO.Implementation.Collections;
7+
using Syncfusion.Drawing;
8+
9+
namespace Create_Excel.Controllers
10+
{
11+
public class HomeController : Controller
12+
{
13+
private readonly ILogger<HomeController> _logger;
14+
15+
public HomeController(ILogger<HomeController> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
public IActionResult Index()
21+
{
22+
return View();
23+
}
24+
25+
public ActionResult CreateExcelDocument()
26+
{
27+
using (ExcelEngine excelEngine = new ExcelEngine())
28+
{
29+
IApplication application = excelEngine.Excel;
30+
application.DefaultVersion = ExcelVersion.Xlsx;
31+
32+
//Create a workbook
33+
IWorkbook workbook = application.Workbooks.Create(1);
34+
IWorksheet worksheet = workbook.Worksheets[0];
35+
36+
//Adding a picture
37+
FileStream imageStream = new FileStream("AdventureCycles-Logo.png", FileMode.Open, FileAccess.Read);
38+
IPictureShape shape = worksheet.Pictures.AddPicture(1, 1, imageStream, 20, 20);
39+
40+
//Disable gridlines in the worksheet
41+
worksheet.IsGridLinesVisible = false;
42+
43+
//Enter values to the cells from A3 to A5
44+
worksheet.Range["A3"].Text = "46036 Michigan Ave";
45+
worksheet.Range["A4"].Text = "Canton, USA";
46+
worksheet.Range["A5"].Text = "Phone: +1 231-231-2310";
47+
48+
//Make the text bold
49+
worksheet.Range["A3:A5"].CellStyle.Font.Bold = true;
50+
51+
//Merge cells
52+
worksheet.Range["D1:E1"].Merge();
53+
54+
//Enter text to the cell D1 and apply formatting.
55+
worksheet.Range["D1"].Text = "INVOICE";
56+
worksheet.Range["D1"].CellStyle.Font.Bold = true;
57+
worksheet.Range["D1"].CellStyle.Font.RGBColor = Color.FromArgb(42, 118, 189);
58+
worksheet.Range["D1"].CellStyle.Font.Size = 35;
59+
60+
//Apply alignment in the cell D1
61+
worksheet.Range["D1"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight;
62+
worksheet.Range["D1"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop;
63+
64+
//Enter values to the cells from D5 to E8
65+
worksheet.Range["D5"].Text = "INVOICE#";
66+
worksheet.Range["E5"].Text = "DATE";
67+
worksheet.Range["D6"].Number = 1028;
68+
worksheet.Range["E6"].Value = "12/31/2018";
69+
worksheet.Range["D7"].Text = "CUSTOMER ID";
70+
worksheet.Range["E7"].Text = "TERMS";
71+
worksheet.Range["D8"].Number = 564;
72+
worksheet.Range["E8"].Text = "Due Upon Receipt";
73+
74+
//Apply RGB backcolor to the cells from D5 to E8
75+
worksheet.Range["D5:E5"].CellStyle.Color = Color.FromArgb(42, 118, 189);
76+
worksheet.Range["D7:E7"].CellStyle.Color = Color.FromArgb(42, 118, 189);
77+
78+
//Apply known colors to the text in cells D5 to E8
79+
worksheet.Range["D5:E5"].CellStyle.Font.Color = ExcelKnownColors.White;
80+
worksheet.Range["D7:E7"].CellStyle.Font.Color = ExcelKnownColors.White;
81+
82+
//Make the text as bold from D5 to E8
83+
worksheet.Range["D5:E8"].CellStyle.Font.Bold = true;
84+
85+
//Apply alignment to the cells from D5 to E8
86+
worksheet.Range["D5:E8"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
87+
worksheet.Range["D5:E5"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;
88+
worksheet.Range["D7:E7"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;
89+
worksheet.Range["D6:E6"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop;
90+
91+
//Enter value and applying formatting in the cell A7
92+
worksheet.Range["A7"].Text = " BILL TO";
93+
worksheet.Range["A7"].CellStyle.Color = Color.FromArgb(42, 118, 189);
94+
worksheet.Range["A7"].CellStyle.Font.Bold = true;
95+
worksheet.Range["A7"].CellStyle.Font.Color = ExcelKnownColors.White;
96+
97+
//Apply alignment
98+
worksheet.Range["A7"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft;
99+
worksheet.Range["A7"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;
100+
101+
//Enter values in the cells A8 to A12
102+
worksheet.Range["A8"].Text = "Steyn";
103+
worksheet.Range["A9"].Text = "Great Lakes Food Market";
104+
worksheet.Range["A10"].Text = "20 Whitehall Rd";
105+
worksheet.Range["A11"].Text = "North Muskegon,USA";
106+
worksheet.Range["A12"].Text = "+1 231-654-0000";
107+
108+
//Create a Hyperlink for e-mail in the cell A13
109+
IHyperLink hyperlink = worksheet.HyperLinks.Add(worksheet.Range["A13"]);
110+
hyperlink.Type = ExcelHyperLinkType.Url;
111+
hyperlink.Address = "[email protected]";
112+
hyperlink.ScreenTip = "Send Mail";
113+
114+
//Merge column A and B from row 15 to 22
115+
worksheet.Range["A15:B15"].Merge();
116+
worksheet.Range["A16:B16"].Merge();
117+
worksheet.Range["A17:B17"].Merge();
118+
worksheet.Range["A18:B18"].Merge();
119+
worksheet.Range["A19:B19"].Merge();
120+
worksheet.Range["A20:B20"].Merge();
121+
worksheet.Range["A21:B21"].Merge();
122+
worksheet.Range["A22:B22"].Merge();
123+
124+
//Enter details of products and prices
125+
worksheet.Range["A15"].Text = " DESCRIPTION";
126+
worksheet.Range["C15"].Text = "QTY";
127+
worksheet.Range["D15"].Text = "UNIT PRICE";
128+
worksheet.Range["E15"].Text = "AMOUNT";
129+
worksheet.Range["A16"].Text = "Cabrales Cheese";
130+
worksheet.Range["A17"].Text = "Chocos";
131+
worksheet.Range["A18"].Text = "Pasta";
132+
worksheet.Range["A19"].Text = "Cereals";
133+
worksheet.Range["A20"].Text = "Ice Cream";
134+
worksheet.Range["C16"].Number = 3;
135+
worksheet.Range["C17"].Number = 2;
136+
worksheet.Range["C18"].Number = 1;
137+
worksheet.Range["C19"].Number = 4;
138+
worksheet.Range["C20"].Number = 3;
139+
worksheet.Range["D16"].Number = 21;
140+
worksheet.Range["D17"].Number = 54;
141+
worksheet.Range["D18"].Number = 10;
142+
worksheet.Range["D19"].Number = 20;
143+
worksheet.Range["D20"].Number = 30;
144+
worksheet.Range["D23"].Text = "Total";
145+
146+
//Apply number format
147+
worksheet.Range["D16:E22"].NumberFormat = "$0.00";
148+
worksheet.Range["E23"].NumberFormat = "$0.00";
149+
150+
//Apply incremental formula for column Amount by multiplying Qty and UnitPrice
151+
application.EnableIncrementalFormula = true;
152+
worksheet.Range["E16:E20"].Formula = "=C16*D16";
153+
154+
//Formula for Sum the total
155+
worksheet.Range["E23"].Formula = "=SUM(E16:E22)";
156+
157+
//Apply borders
158+
worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
159+
worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
160+
worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Grey_25_percent;
161+
worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Grey_25_percent;
162+
worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
163+
worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
164+
worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Black;
165+
worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Black;
166+
167+
//Apply font setting for cells with product details
168+
worksheet.Range["A3:E23"].CellStyle.Font.FontName = "Arial";
169+
worksheet.Range["A3:E23"].CellStyle.Font.Size = 10;
170+
worksheet.Range["A15:E15"].CellStyle.Font.Color = ExcelKnownColors.White;
171+
worksheet.Range["A15:E15"].CellStyle.Font.Bold = true;
172+
worksheet.Range["D23:E23"].CellStyle.Font.Bold = true;
173+
174+
//Apply cell color
175+
worksheet.Range["A15:E15"].CellStyle.Color = Color.FromArgb(42, 118, 189);
176+
177+
//Apply alignment to cells with product details
178+
worksheet.Range["A15"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft;
179+
worksheet.Range["C15:C22"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
180+
worksheet.Range["D15:E15"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
181+
182+
//Apply row height and column width to look good
183+
worksheet.Range["A1"].ColumnWidth = 36;
184+
worksheet.Range["B1"].ColumnWidth = 11;
185+
worksheet.Range["C1"].ColumnWidth = 8;
186+
worksheet.Range["D1:E1"].ColumnWidth = 18;
187+
worksheet.Range["A1"].RowHeight = 47;
188+
worksheet.Range["A2"].RowHeight = 15;
189+
worksheet.Range["A3:A4"].RowHeight = 15;
190+
worksheet.Range["A5"].RowHeight = 18;
191+
worksheet.Range["A6"].RowHeight = 29;
192+
worksheet.Range["A7"].RowHeight = 18;
193+
worksheet.Range["A8"].RowHeight = 15;
194+
worksheet.Range["A9:A14"].RowHeight = 15;
195+
worksheet.Range["A15:A23"].RowHeight = 18;
196+
197+
//Saving the Excel to the MemoryStream
198+
MemoryStream stream = new MemoryStream();
199+
workbook.SaveAs(stream);
200+
201+
//Set the position as '0'.
202+
stream.Position = 0;
203+
204+
//Download Excel document in the browser.
205+
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Sample.xlsx");
206+
}
207+
208+
}
209+
public IActionResult Privacy()
210+
{
211+
return View();
212+
}
213+
214+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
215+
public IActionResult Error()
216+
{
217+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
218+
}
219+
}
220+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>Create_Excel</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="29.2.5" />
12+
</ItemGroup>
13+
14+
</Project>
205 KB
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Create_Excel.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
builder.Services.AddControllersWithViews();
5+
6+
var app = builder.Build();
7+
8+
// Configure the HTTP request pipeline.
9+
if (!app.Environment.IsDevelopment())
10+
{
11+
app.UseExceptionHandler("/Home/Error");
12+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
13+
app.UseHsts();
14+
}
15+
16+
app.UseHttpsRedirection();
17+
app.UseStaticFiles();
18+
19+
app.UseRouting();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllerRoute(
24+
name: "default",
25+
pattern: "{controller=Home}/{action=Index}/{id?}");
26+
27+
app.Run();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:59144",
8+
"sslPort": 44307
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5181",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7058;http://localhost:5181",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@{
2+
Html.BeginForm("CreateExcelDocument", "Home", FormMethod.Get);
3+
{
4+
<div>
5+
<input type="submit" value="Create Excel document" style="width:200px;height:27px" />
6+
</div>
7+
}
8+
Html.EndForm();
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>

0 commit comments

Comments
 (0)