Skip to main content Skip to footer

How to deploy an Excel API to Azure, cloud in 6 steps

Take advantage of GrapeCity Documents for Excel and work with Excel documents with full feature support on Azure. Here are the steps needed to create a basic Documents for Excel web app and deploy it to Azure.

Step 1: Create a new ASP.NET Core MVC app

In Visual Studio, go to File > New > Project, and select ASP.NET Core Web Application

In the wizard that opens, select .NET Core – ASP.NET Core 2.0 – Web Application (Model-View-Controller) then click OK.

Step 2: Add reference to GrapeCity.Documents.Excel

Go to Dependencies > Manage NuGet Packages, and install the GrapeCity.Documents.Excel package.

Step 3: Clean up the Index.cshtml page

Clean up the Index.cshtml page (under Views\Home), so that it contains just this (this step is optional, as our controller will send XLSX content for this page):

Index.cshtml

@{
    ViewData["Title"] = "Home Page";
}
<div class="row">
</div>

Step 4: Modify HomeController.cs

Modify HomeController.cs (under Controllers) to generate the 'Hello, World!' Excel document.

And the following usings:

using System.IO;
using GrapeCity.Documents.Excel;

Modify the Index() method like so:

public IActionResult Index()
{
    // Create the 'Hello, World!' Excel document:
    var workbook = new Workbook();
    var worksheet = workbook.ActiveSheet;
    worksheet.Range["B2"].Value = "Hello, World!";

    // Save it to a memory stream:
    MemoryStream ms = new MemoryStream();
    workbook.Save(ms, SaveFileFormat.Xlsx);
    ms.Seek(0, SeekOrigin.Begin);

    // Send it back to the web page:
    Response.Headers["Content-Disposition"] = "inline; filename=\"HelloWorld.xlsx\"";
    return new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}

Step 5: Test the app

From Visual Studio, run your app locally to make sure everything works. You should see the "Hello, World!" PDF opening in your default web browser.

Step 6: Publish the app to Azure

Go to to Build > Publish, create a new 'Microsoft Azure App Service' publish profile, select appropriate name, subscription details etc. The defaults should work just fine.

Get the code to publish Excel API to Azure

Try GrapeCity Documents for Excel

Shilpa Sharma - Product Manager

Shilpa Sharma

Product Manager
comments powered by Disqus