Nothing Special   »   [go: up one dir, main page]

Skip to content

ClosedXML/ClosedXML.Extensions.WebApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClosedXML.Extensions.WebApi

WebApi Extensions for ClosedXML

Install via NuGet

To install ClosedXML.Extensions.WebApi, run the following command in the Package Manager Console

PM> Install-Package ClosedXML.Extensions.WebApi

or

dotnet add package ClosedXML.Extensions.WebApi

Usage

In your WebApi controller define an action that will generate and download your file:

public class ExcelController : ApiController
{
    [HttpGet]
    [Route("api/file/{id}")]
    public async Task<HttpResponseMessage> DownloadFile(int id)
    {
        var wb = await BuildExcelFile(id);
        return wb.Deliver("excelfile.xlsx");
    }

    private async Task<XLWorkbook> BuildExcelFile(int id)
    {
        //Creating the workbook
        var t = Task.Run(() =>
        {
            var wb = new XLWorkbook();
            var ws = wb.AddWorksheet("Sheet1");
            ws.FirstCell().SetValue(id);

            return wb;
        });

        return await t;
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages