Skip to content
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

Download excel #1

Open
wants to merge 2 commits into
base: product-crud
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -58,6 +58,10 @@ <h2>{{ "Products" | localize }}</h2>
<mat-icon>delete</mat-icon>
<span>{{ "Delete" | localize }}</span>
</button>
<button mat-menu-item (click)="download()">
<mat-icon>download</mat-icon>
<span>Download</span>
</button>
</mat-menu>
</td>
</tr>
@@ -1,3 +1,4 @@
import { ApiServiceProxy } from './../../shared/service-proxies/service-proxies';
import { Component, Injector } from '@angular/core';
import { MatDialog } from '@angular/material';
import { finalize } from 'rxjs/operators';
@@ -12,6 +13,7 @@ import {
} from '@shared/service-proxies/service-proxies';
import { CreateProductDialogComponent } from './create-product/create-product-dialog.component';
import { EditProductDialogComponent } from './edit-product/edit-product-dialog.component';
import * as moment from 'moment';

@Component({
templateUrl: './products.component.html',
@@ -32,7 +34,8 @@ export class ProductsComponent extends PagedListingComponentBase<ProductDto> {
constructor(
injector: Injector,
private _productService: ProductsServiceProxy,
private _dialog: MatDialog
private _dialog: MatDialog,
private apiServiceProxy: ApiServiceProxy,
) {
super(injector);
}
@@ -99,4 +102,15 @@ export class ProductsComponent extends PagedListingComponentBase<ProductDto> {
}
});
}

public download() {
const fileName = moment().format('YYYY-MM-DD');
this.apiServiceProxy.productFiles(fileName)
.subscribe(fileResponse => {
const a = document.createElement('a');
a.href = URL.createObjectURL(fileResponse.data);
a.download = fileName + '.xlsx';
a.click();
});
}
}

Large diffs are not rendered by default.

@@ -14,6 +14,7 @@ import * as ApiServiceProxies from './service-proxies';
ApiServiceProxies.AccountServiceProxy,
ApiServiceProxies.ConfigurationServiceProxy,
ApiServiceProxies.ProductsServiceProxy,
ApiServiceProxies.ApiServiceProxy,
{ provide: HTTP_INTERCEPTORS, useClass: AbpHttpInterceptor, multi: true }
]
})
@@ -0,0 +1,33 @@
using System.Net;
using System.Threading.Tasks;
using Abp.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml;

namespace LeesStore.Controllers
{
[Route("api/[controller]")]
public class ProductFilesController : AbpController
{
[HttpPost]
[Route("{filename}.xlsx")]
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
public ActionResult Download(string fileName)
{
var fileMemoryStream = GenerateReportAndWriteToMemoryStream();
return File(fileMemoryStream,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
fileName + ".xlsx");
}

private byte[] GenerateReportAndWriteToMemoryStream()
{
using (ExcelPackage package = new ExcelPackage())
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Data");
worksheet.Cells[1, 1].Value = "Hello World";
return package.GetAsByteArray();
}
}
}
}
@@ -20,6 +20,7 @@
<ProjectReference Include="..\LeesStore.EntityFrameworkCore\LeesStore.EntityFrameworkCore.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EPPlus" Version="4.5.3.2" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
@@ -64,6 +64,11 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
// Swagger - Enable this line and the related lines in Configure method to enable swagger UI
services.AddSwaggerGen(options =>
{
options.MapType<FileContentResult>(() => new Schema
{
Type = "file"
});

options.SwaggerDoc("v1", new Info { Title = "LeesStore API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);

@@ -75,6 +80,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
In = "header",
Type = "apiKey"
});

});

// Configure Abp and Dependency Injection
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.