Data Export
The data export function allows users to download query results as Excel files.
Export Interface
- URL:
/api/app/{entity-name}/export-excel - Method:
GET - Parameters: Same filtering parameters as the
GetListinterface (to ensure the exported data matches the current view).
Implementation Logic
- Query: Retrieve data from the database based on the filter conditions.
- Mapping: Convert entity objects into a flat DTO structure suitable for export (ExportDto).
- Generation: Generate the Excel file stream using the Excel library.
- Response: Return the file stream with the MIME type
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.
public async Task<IRemoteStreamContent> GetListAsExcelFileAsync(GetIdentityUsersInput input)
{
var users = await _userRepository.GetListAsync(...);
var excelBytes = _excelService.Generate(users);
return new RemoteStreamContent(new MemoryStream(excelBytes), "Users.xlsx");
}