Skip to content

Commit 3314cad

Browse files
Added the samples
0 parents  commit 3314cad

File tree

125 files changed

+52744
-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.

125 files changed

+52744
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using ImportHtmlTable.Models;
8+
9+
namespace ImportHtmlTable.Controllers
10+
{
11+
public class HomeController : Controller
12+
{
13+
public IActionResult Index()
14+
{
15+
return View();
16+
}
17+
18+
public IActionResult About()
19+
{
20+
ViewData["Message"] = "Your application description page.";
21+
22+
return View();
23+
}
24+
25+
public IActionResult Contact()
26+
{
27+
ViewData["Message"] = "Your contact page.";
28+
29+
return View();
30+
}
31+
32+
public IActionResult Privacy()
33+
{
34+
return View();
35+
}
36+
37+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
38+
public IActionResult Error()
39+
{
40+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
41+
}
42+
}
43+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Syncfusion.XlsIO;
10+
11+
namespace ImportHtmlTable.Controllers
12+
{
13+
public class ImportHtmlTableController : Controller
14+
{
15+
private readonly IHostingEnvironment _hostingEnvironment;
16+
17+
public ImportHtmlTableController(IHostingEnvironment hostingEnvironment)
18+
{
19+
_hostingEnvironment = hostingEnvironment;
20+
}
21+
22+
public ActionResult ImportHtmlTable(string button, string tableHTML)
23+
{
24+
if (button == null)
25+
return View();
26+
27+
MemoryStream ms = new MemoryStream();
28+
29+
// The instantiation process consists of two steps.
30+
// Step 1 : Instantiate the spreadsheet creation engine.
31+
using (ExcelEngine excelEngine = new ExcelEngine())
32+
{
33+
34+
// Step 2 : Instantiate the excel application object.
35+
IApplication application = excelEngine.Excel;
36+
application.DefaultVersion = ExcelVersion.Excel2016;
37+
38+
// A workbook is created.
39+
IWorkbook workbook = application.Workbooks.Create(1);
40+
41+
// The first worksheet object in the worksheets collection is accessed.
42+
IWorksheet worksheet = workbook.Worksheets[0];
43+
44+
byte[] byteArray = Encoding.UTF8.GetBytes(tableHTML);
45+
46+
MemoryStream file = new MemoryStream(byteArray);
47+
48+
// Imports HTML table into the worksheet from first row and first column
49+
worksheet.ImportHtmlTable(file, 1, 1);
50+
51+
worksheet.UsedRange.AutofitColumns();
52+
worksheet.UsedRange.AutofitRows();
53+
54+
workbook.SaveAs(ms);
55+
ms.Position = 0;
56+
}
57+
58+
return File(ms, "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Export-HTML-Table.xlsx");
59+
}
60+
}
61+
62+
}
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>netcoreapp2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.App" />
9+
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
10+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.9" />
11+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="18.2.0.54" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.1022
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImportHtmlTable", "ImportHtmlTable.csproj", "{9E7C9A6D-2EA1-4E70-A52A-206754127656}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug-Xml|Any CPU = Debug-Xml|Any CPU
12+
Release|Any CPU = Release|Any CPU
13+
Release-Xml|Any CPU = Release-Xml|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Debug-Xml|Any CPU.ActiveCfg = Debug|Any CPU
19+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Debug-Xml|Any CPU.Build.0 = Debug|Any CPU
20+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU
23+
{9E7C9A6D-2EA1-4E70-A52A-206754127656}.Release-Xml|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {B12E0E54-B7A0-4A08-80EC-659D04F95923}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace ImportHtmlTable.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace ImportHtmlTable
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
CreateWebHostBuilder(args).Build().Run();
18+
}
19+
20+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>();
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:56336",
7+
"sslPort": 44383
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"ImportHtmlTable": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
}
25+
}
26+
}
27+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.AspNetCore.HttpsPolicy;
9+
using Microsoft.AspNetCore.Mvc;
10+
using Microsoft.Extensions.Configuration;
11+
using Microsoft.Extensions.DependencyInjection;
12+
13+
namespace ImportHtmlTable
14+
{
15+
public class Startup
16+
{
17+
public Startup(IConfiguration configuration)
18+
{
19+
Configuration = configuration;
20+
}
21+
22+
public IConfiguration Configuration { get; }
23+
24+
// This method gets called by the runtime. Use this method to add services to the container.
25+
public void ConfigureServices(IServiceCollection services)
26+
{
27+
services.Configure<CookiePolicyOptions>(options =>
28+
{
29+
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
30+
options.CheckConsentNeeded = context => true;
31+
options.MinimumSameSitePolicy = SameSiteMode.None;
32+
});
33+
34+
35+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
36+
}
37+
38+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
39+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
40+
{
41+
if (env.IsDevelopment())
42+
{
43+
app.UseDeveloperExceptionPage();
44+
}
45+
else
46+
{
47+
app.UseExceptionHandler("/Home/Error");
48+
app.UseHsts();
49+
}
50+
51+
app.UseHttpsRedirection();
52+
app.UseStaticFiles();
53+
app.UseCookiePolicy();
54+
55+
app.UseMvc(routes =>
56+
{
57+
routes.MapRoute(
58+
name: "default",
59+
template: "{controller=ImportHtmlTable}/{action=ImportHtmlTable}/{id?}");
60+
});
61+
}
62+
}
63+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@{
2+
ViewData["Title"] = "About";
3+
}
4+
<h2>@ViewData["Title"]</h2>
5+
<h3>@ViewData["Message"]</h3>
6+
7+
<p>Use this area to provide additional information.</p>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@{
2+
ViewData["Title"] = "Contact";
3+
}
4+
<h2>@ViewData["Title"]</h2>
5+
<h3>@ViewData["Message"]</h3>
6+
7+
<address>
8+
One Microsoft Way<br />
9+
Redmond, WA 98052-6399<br />
10+
<abbr title="Phone">P:</abbr>
11+
425.555.0100
12+
</address>
13+
14+
<address>
15+
<strong>Support:</strong> <a href="mailto:Support@example.com">Support@example.com</a><br />
16+
<strong>Marketing:</strong> <a href="mailto:Marketing@example.com">Marketing@example.com</a>
17+
</address>

0 commit comments

Comments
 (0)