Skip to content

Commit

Permalink
wip - complex excel download demo setup
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulrahmanshabeekmohamed committed Dec 14, 2024
1 parent cb2ad74 commit 7084fdd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
32 changes: 17 additions & 15 deletions ReportDemoComponents/ComplexClosedXMLDemo.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@using ClosedXML.Excel
@using ClosedXML.Report
@using Microsoft.JSInterop

Expand All @@ -24,12 +23,13 @@
private IJSObjectReference? module;
private string? base64String;

[Inject] private TableOfContents tableOfContents { get; set; } = default!;
[Inject] private TableOfContents TableOfContents { get; set; } = default!;
[Inject] private IJSRuntime JSRuntime { get; set; } = default!;
[Inject] private HttpClient HttpClient { get; set; } = default!;

protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
var data = tableOfContents.AllContents;
var data = TableOfContents.AllContents;

var complexData = new
{
Expand Down Expand Up @@ -58,20 +58,22 @@
}).ToList()
};

// var template = new XLTemplate(@"ILoveDotNetContentTemplate.xlsx");
var file = await HttpClient.GetStreamAsync("./files/ILoveDotNetContentTemplate.xlsx");

@* var template = new XLTemplate(file);
// template.AddVariable(complexData);
// template.Generate();
// template.Workbook.Worksheets
// .Worksheet(template.Workbook.Worksheets.First().Name)
// .ColumnsUsed()
// .AdjustToContents();
template.AddVariable(complexData);
template.Generate();
template.Workbook.Worksheets
.Worksheet(template.Workbook.Worksheets.First().Name)
.ColumnsUsed()
.AdjustToContents();
// using var stream = new MemoryStream();
// template.SaveAs(stream);
using var stream = new MemoryStream();
template.SaveAs(stream);
// var bytes = stream.ToArray();
// base64String = Convert.ToBase64String(bytes);
var bytes = stream.ToArray();
base64String = Convert.ToBase64String(bytes); *@
}

protected override async Task OnAfterRenderAsync(bool firstRender)
Expand Down
11 changes: 11 additions & 0 deletions ReportDemoComponents/Pages/Blogs/GenerateClosedXMLExcel.razor
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@
I attempted to export complex real-world data from I Love .NET, and the output is as follows. You can alos notice how Generated Date get formatted as expected.
</p>

<ErrorBoundary>
<ChildContent>
<ComplexClosedXMLDemo></ComplexClosedXMLDemo>
</ChildContent>
<ErrorContent>
<div class="[ bg-red-500 ]">
<p class="[ text-white ]">An error occured while downloading the excel. Please try again later.</p>
</div>
</ErrorContent>
</ErrorBoundary>

<p>Template:</p>

<figure>
Expand Down
1 change: 1 addition & 0 deletions ReportDemoComponents/ReportDemoComponents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.104.2" />
<PackageReference Include="ClosedXML.Report" Version="0.2.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="9.0.0" />
<PackageReference Include="QuestPDF" Version="2202.8.2" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions ReportDemoComponents/SimpleClosedXMLDemo.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
private IJSObjectReference? module;
private string? base64String;

[Inject] private TableOfContents tableOfContents { get; set; } = default!;
[Inject] private TableOfContents TableOfContents { get; set; } = default!;
[Inject] private IJSRuntime JSRuntime { get; set; } = default!;

protected override void OnInitialized()
{
var data = tableOfContents.AllContents;
var data = TableOfContents.AllContents;
var table = data.ToDataTable("contents");

using var wb = new XLWorkbook();
Expand Down

0 comments on commit 7084fdd

Please sign in to comment.