Skip to content

Commit 3712c6a

Browse files
Added the samples
0 parents  commit 3712c6a

Some content is hidden

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

57 files changed

+2673
-0
lines changed

ClientSideApplication/App.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="18.4.0.42" />
13+
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
14+
</ItemGroup>
15+
16+
</Project>
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 Version 16
4+
VisualStudioVersion = 16.0.30709.132
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSideApplication", "ClientSideApplication.csproj", "{89C95A4A-4041-4994-953C-1F14775C97CD}"
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+
{89C95A4A-4041-4994-953C-1F14775C97CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{89C95A4A-4041-4994-953C-1F14775C97CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{89C95A4A-4041-4994-953C-1F14775C97CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{89C95A4A-4041-4994-953C-1F14775C97CD}.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 = {E0BB0DB8-0DA0-40EF-B52A-32AAE58E62C7}
24+
EndGlobalSection
25+
EndGlobal

ClientSideApplication/FileUtils.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.JSInterop;
6+
7+
namespace ClientSideApplication
8+
{
9+
public static class FileUtils
10+
{
11+
public static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
12+
=> js.InvokeAsync<object>(
13+
"saveAsFile",
14+
filename,
15+
Convert.ToBase64String(data));
16+
}
17+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@page "/Excel"
2+
@using Syncfusion.XlsIO;
3+
@using Syncfusion.Drawing;
4+
@using System.IO;
5+
@inject Microsoft.JSInterop.IJSRuntime JS
6+
@using System.Data;
7+
8+
<h2>Syncfusion Excel library (Essential XlsIO)</h2>
9+
<p>Syncfusion Excel library (Essential XlsIO) is a Blazor Excel library used to create, read, edit, and convert Excel files in your applications without Microsoft Office dependencies.</p>
10+
<button class="btn btn-primary" @onclick="@CreateDocument">Create Document</button>
11+
12+
@code{
13+
/// <summary>
14+
/// Create an Excel document
15+
/// </summary>
16+
public async void CreateDocument()
17+
{
18+
//Create an instance of ExcelEngine
19+
using (ExcelEngine excelEngine = new ExcelEngine())
20+
{
21+
IApplication application = excelEngine.Excel;
22+
application.DefaultVersion = ExcelVersion.Xlsx;
23+
24+
//Create a workbook
25+
IWorkbook workbook = application.Workbooks.Create(1);
26+
IWorksheet worksheet = workbook.Worksheets[0];
27+
28+
//Initialize DataTable and data get from SampleDataTable method
29+
DataTable table = SampleDataTable();
30+
31+
//Import data from DataTable
32+
worksheet.ImportDataTable(table, true, 1, 1);
33+
34+
worksheet.UsedRange.AutofitColumns();
35+
36+
37+
//Save the document as a stream and retrun the stream.
38+
using (MemoryStream stream = new MemoryStream())
39+
{
40+
//Save the created Excel document to MemoryStream
41+
workbook.SaveAs(stream);
42+
43+
//Download the excel file
44+
await JS.SaveAs("Sample.xlsx", stream.ToArray());
45+
}
46+
}
47+
}
48+
private DataTable SampleDataTable()
49+
{
50+
DataTable reports = new DataTable();
51+
reports.Columns.Add("SalesPerson");
52+
reports.Columns.Add("Age", typeof(int));
53+
reports.Columns.Add("Salary", typeof(int));
54+
reports.Rows.Add("Andy Bernard", 21, 30000);
55+
reports.Rows.Add("Jim Halpert", 25, 40000);
56+
reports.Rows.Add("Karen Fillippelli", 30, 50000);
57+
reports.Rows.Add("Phyllis Lapin", 34, 39000);
58+
reports.Rows.Add("Stanley Hudson", 45, 58000);
59+
60+
return reports;
61+
}
62+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@page "/"
2+
3+
<h1>Hello, world!</h1>
4+
5+
Welcome to your new app.
6+
7+
<SurveyPrompt Title="How is Blazor working for you?" />

ClientSideApplication/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Logging;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Net.Http;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace ClientSideApplication
12+
{
13+
public class Program
14+
{
15+
public static async Task Main(string[] args)
16+
{
17+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
18+
builder.RootComponents.Add<App>("app");
19+
20+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
21+
22+
await builder.Build().RunAsync();
23+
}
24+
}
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:55346",
7+
"sslPort": 44399
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"ClientSideApplication": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
23+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">ClientSideApplication</a>
3+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="excel">
17+
<span class="oi oi-list-rich" aria-hidden="true"></span> Excel
18+
</NavLink>
19+
</li>
20+
</ul>
21+
</div>
22+
23+
@code {
24+
private bool collapseNavMenu = true;
25+
26+
private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
27+
28+
private void ToggleNavMenu()
29+
{
30+
collapseNavMenu = !collapseNavMenu;
31+
}
32+
}

0 commit comments

Comments
 (0)