Skip to main content

RSCG_WebAPIExports by Andrei Ignat

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: RSCG_WebAPIExports

Add Excel export to your WebAPI

Author: Andrei Ignat

NuGet: https://www.nuget.org/packages/RSCG_WebAPIExports/

You can find more details at https://github.com/ignatandrei/RSCG_WebAPIExports/

Source : https://github.com/ignatandrei/RSCG_WebAPIExports/

Original Readme

note

RSCG_WebAPIExports

RSCG_WebAPIExports

Add exports to file to WebAPI ( for the moment, just Excel / xlsx)

How to use in WebAPI project

Add reference to the package in the .csproj

<PackageReference Include="RSCG_WebAPIExports" Version="2023.8.16.1255" OutputItemType="Analyzer" ReferenceOutputAssembly="true"  />
<!--
<PackageReference Include="RSCG_WebAPIExports" Version="2023.8.16.1255" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
<PackageReference Include="ArrayToExcel" Version="2.2.2" />
-->

Then in the WebAPI add

using WebApiExportToFile;
//code
// Add services to the container.
//WebApiExportToFile.AddExport(builder.Services);
builder.Services.AddExport();
var app = builder.Build();
app.UseExport();

Add to any url : .xlsx ( e.g. for /WeatherForecast put /WeatherForecast.xlsx ) and the excel will be

downloaded

About

note

Generating Excel from WebAPI json array

How to use

Example ( source csproj, source files )

This is the CSharp Project that references RSCG_WebAPIExports

<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="RSCG_WebAPIExports" Version="2023.8.16.1255" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="ArrayToExcel" Version="2.2.2" />

</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

using Microsoft.AspNetCore.Rewrite;
namespace WebApiExportToFile;
#nullable enable
public static partial class Extensions
{
static partial void AddReturnTypesFromGenerator();
public static IServiceCollection AddExport(this IServiceCollection services, params Type[]? typesReturnedByActions)
{
AddReturnTypesFromGenerator();
//MiddlewareExportToFile.AddReturnType(typeof(Person[]));
//MiddlewareExportToFile.AddReturnType(typeof(WeatherForecast[]));
MiddlewareExportToFile.AddReturnTypes(typesReturnedByActions);

return services.AddSingleton<MiddlewareExportToFile>();
}
public static IApplicationBuilder UseExport(this IApplicationBuilder app)
{
app.UseMiddleware<MiddlewareExportToFile>();
var options = new RewriteOptions().Add(MiddlewareExportToFile.RewriteExtNeeded);
app.UseRewriter(options);
return app;
}
}

#nullable disable

Usefull

Download Example (.NET C# )

Share RSCG_WebAPIExports

https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_WebAPIExports

In the same category (API) - 6 other generators

Microsoft.Extensions.Configuration.Binder

MinimalApiBuilder

RDG

Refit

SafeRouting

SkinnyControllersCommon