Update SurveyLib and add Excel export functionality
This commit is contained in:
parent
690eaaa32f
commit
837f90db52
5 changed files with 37 additions and 1 deletions
|
|
@ -0,0 +1,26 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyLib.Tools.Tools;
|
||||
|
||||
namespace SurveyBackend.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/export")]
|
||||
public class ExportController
|
||||
{
|
||||
private readonly TableExporter _tableExporter;
|
||||
|
||||
public ExportController(TableExporter tableExporter)
|
||||
{
|
||||
_tableExporter = tableExporter;
|
||||
}
|
||||
|
||||
[HttpGet("excel/{surveyId:int}")]
|
||||
public async Task<IActionResult> ExportSurveyById(int surveyId)
|
||||
{
|
||||
var fileBytes = await _tableExporter.ExportDataBySurveyIdAsync(surveyId);
|
||||
return new FileContentResult(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
{
|
||||
FileDownloadName = $"survey_{surveyId}_{DateTime.UtcNow:yyyyMMdd_HHmmss}.xlsx"
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue