No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src Upgrade to ClosedXML 0.93 Jun 29, 2018
.gitattributes First commit May 14, 2018
.gitignore First commit May 14, 2018
LICENSE Initial commit May 14, 2018
README.md First commit May 14, 2018

README.md

ClosedXML.Extensions.WebApi

WebApi Extensions for ClosedXML

Install via NuGet

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

PM> Install-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;
    }
}