Skip to content

update project #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @DevExpressExampleBot
22 changes: 22 additions & 0 deletions CS/BlazorAppSpreadsheet.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAppSpreadsheet", "BlazorAppSpreadsheet\BlazorAppSpreadsheet.csproj", "{320F556D-39EC-4DB7-BC8B-5561F93279DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{320F556D-39EC-4DB7-BC8B-5561F93279DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{320F556D-39EC-4DB7-BC8B-5561F93279DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{320F556D-39EC-4DB7-BC8B-5561F93279DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{320F556D-39EC-4DB7-BC8B-5561F93279DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DevExpress.Blazor" Version="24.2.1-alpha-24207" />
<PackageReference Include="DevExpress.Document.Processor" Version="24.2.1-alpha-24207" />
<Content Remove="Components\Layout\NavMenu.razor" />
</ItemGroup>

<ItemGroup>
<None Remove="Components\Layout\NavMenu.razor.css" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="DevExpress.Blazor" Version="24.2.3" />
<PackageReference Include="DevExpress.Document.Processor" Version="24.2.3" />
<PackageReference Include="DevExpress.Drawing.Skia" Version="24.2.3" />
</ItemGroup>

<ItemGroup>
<None Update="Data\LoanAmortizationScheduleTemplate.xltx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Drawing;
using DevExpress.Spreadsheet;

namespace BlazorApp_SpreadsheetDocumentAPI
namespace BlazorAppSpreadsheet
{
public class LoanAmortizationScheduleGenerator
{
Expand Down Expand Up @@ -203,4 +203,4 @@ void SpecifyPrintOptions()
Sheet.PrintOptions.FitToHeight = 0;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.IO;
using System.Threading.Tasks;
using BlazorAppSpreadsheet;
using DevExpress.Spreadsheet;

namespace BlazorApp_SpreadsheetDocumentAPI
namespace BlazorAppSpreadsheet
{
public class DocumentService
{
Expand Down Expand Up @@ -58,4 +59,4 @@ async Task<Workbook> GenerateDocumentAsync(double loanAmount,
return workbook;
}
}
}
}
22 changes: 22 additions & 0 deletions CS/BlazorAppSpreadsheet/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="BlazorAppSpreadsheet.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.css" rel="stylesheet" />

<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>

</html>
21 changes: 21 additions & 0 deletions CS/BlazorAppSpreadsheet/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@inherits LayoutComponentBase

<div class="page">

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.css" rel="stylesheet" />
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
36 changes: 36 additions & 0 deletions CS/BlazorAppSpreadsheet/Components/Pages/Error.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics

<PageTitle>Error</PageTitle>

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }

private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@page "/"
@rendermode InteractiveServer
@using System.Globalization
@using Microsoft.AspNetCore.WebUtilities
@inject DocumentService DocumentService
@inject IJSRuntime JS

Expand All @@ -8,10 +11,11 @@
<DxFormLayoutItem ColSpanMd="12">
<Template>
<p>
This example uses the
<a href="https://www.devexpress.com/products/net/office-file-api/spreadsheet/">Spreadsheet Document API</a>
to create a loan amortization schedule. Specify the loan amount, loan period in years,
annual interest rate, and start date to calculate your loan payments. Click <b>Export to XLSX</b>
This example uses the Spreadsheet Document API
to create a loan amortization schedule.
Specify the loan amount, loan period in years,
annual interest rate, and start date to calculate
your loan payments. Click <b>Export to XLSX</b>
or <b>Export to PDF</b> to save the result as XLSX or PDF.
</p>
</Template>
Expand Down Expand Up @@ -66,14 +70,14 @@

<DxFormLayoutItem ColSpanMd="12">
<Template>
<iframe class="col p-0 preview" height="500" src="@content"/>
<iframe class="col p-0 preview" height="500" width="1100" src="@content" />
</Template>
</DxFormLayoutItem>
</DxFormLayoutGroup>
</DxFormLayout>
</div>

@code{
@code {
string content = String.Empty;
double loanAmount = 19000;
int periodInYears = 2;
Expand Down Expand Up @@ -121,10 +125,10 @@
content = "data:text/html;base64," + Convert.ToBase64String(document);
}

void ExportToXlsx(MouseEventArgs args) => JS.InvokeAsync<object>("open",
async Task ExportToXlsx(MouseEventArgs args) => await JS.InvokeAsync<object>("open",
GetQueryString("api/Export/Xlsx"), "_self");

void ExportToPdf(MouseEventArgs args) => JS.InvokeAsync<object>("open",
async Task ExportToPdf(MouseEventArgs args) => await JS.InvokeAsync<object>("open",
GetQueryString("api/Export/Pdf"), "_self");

string GetQueryString(string uri)
Expand All @@ -137,4 +141,4 @@
};
return QueryHelpers.AddQueryString(uri, queryParams);
}
}
}
6 changes: 6 additions & 0 deletions CS/BlazorAppSpreadsheet/Components/Routes.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@using System.Net.Http
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using BlazorApp_SpreadsheetDocumentAPI
@using BlazorApp_SpreadsheetDocumentAPI.Shared
@using BlazorAppSpreadsheet
@using BlazorAppSpreadsheet.Components
@using DevExpress.Blazor
@using Microsoft.AspNetCore.WebUtilities
@using System.Globalization
@using static Microsoft.AspNetCore.Components.Web.RenderMode
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BlazorApp_SpreadsheetDocumentAPI;
using BlazorAppSpreadsheet;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace BlazorApp_SpreadsheetAPI.Controllers
namespace BlazorAppSpreadsheet
{
[Route("api/[controller]")]
[ApiController]
Expand All @@ -18,25 +18,25 @@ public ExportController(DocumentService documentService)

[HttpGet]
[Route("[action]")]
public async Task<IActionResult> Xlsx([FromQuery] double loanAmount,
[FromQuery] int periodInYears, [FromQuery] double interestRate,
public async Task<IActionResult> Xlsx([FromQuery] double loanAmount,
[FromQuery] int periodInYears, [FromQuery] double interestRate,
[FromQuery] DateTime loanStartDate)
{
var document = await documentService.GetXlsxDocumentAsync(loanAmount, periodInYears,
var document = await documentService.GetXlsxDocumentAsync(loanAmount, periodInYears,
interestRate, loanStartDate);
return File(document, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
return File(document, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"output.xlsx");
}

[HttpGet]
[Route("[action]")]
public async Task<IActionResult> Pdf([FromQuery] double loanAmount,
[FromQuery] int periodInYears, [FromQuery] double interestRate,
public async Task<IActionResult> Pdf([FromQuery] double loanAmount,
[FromQuery] int periodInYears, [FromQuery] double interestRate,
[FromQuery] DateTime loanStartDate)
{
var document = await documentService.GetPdfDocumentAsync(loanAmount, periodInYears,
var document = await documentService.GetPdfDocumentAsync(loanAmount, periodInYears,
interestRate, loanStartDate);
return File(document, "application/pdf", "output.pdf");
}
}
}
}
42 changes: 42 additions & 0 deletions CS/BlazorAppSpreadsheet/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using BlazorAppSpreadsheet.Components;

namespace BlazorAppSpreadsheet
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddDevExpressBlazor();
builder.Services.AddSingleton<DocumentService>();

var app = builder.Build();


// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();
app.UseAntiforgery();


app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.MapControllers();
app.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
Loading
Loading