Spread.Services Documentation
Apply License to Spread.Services
Spread.Services Documentation > Developer's Guide > Get Started > Apply License to Spread.Services

Applying license to Spread.Services involves completing the following steps to create and license a WorkBook:

Step 1: Create a new Web Application (.NET Core)

  1. In Visual Studio, select File | New | Project to create a new ASP.NET Core Web Application.
  2. Under installed templates, select Visual C# | Web | ASP.NET Core Web Application, and then click OK.
  3. In the New ASP.NET Core Web Application(.NET Core) dialog, select Web Application, and then click OK.
  4. Add the Spread.Services references to the project. In the Solution Explorer, right click Dependencies and select Manage NuGet Packages. In NuGet Package Manager, select nuget.org as the Package source. Search for Spread.Services package, and click Install.

Step 2: Add a Controller

  1. In the Solution Explorer, right click the folder Controllers.
  2. From the context menu, select Add | New Item. The Add New Item dialog appears.
  3. Complete the following steps in the Add New Item dialog:
    1. Expand the Installed tab towards left, and select ASP.NET|MVC Controller Class.
    2. Set name of the controller (For example: SpreadController).
    3. Click Add.
  4. Add the product license key. For example, LicenseManager.SetLicense("Your License Key").
  5. Add the following code to replace the Index() method.
    SpreadController.cs
    Copy Code
    public IActionResult Index()
            {
                //Apply license before using the API, otherwise it will be considered as no license.
                //Apply the license only once for an application
                LicenseManager.SetLicense("Your License Key")
                Workbook workbook = new Workbook();
                IWorksheet worksheet = workbook.Worksheets[0];
                worksheet.Range["A1:A3"].Value = 121;
                workbook.Save("Workbook.xlsx");
                return View();
            }

 

A new controller is added to the application within the folder Controllers.

Step 3: Add a View

  1. From the Solution Explorer, right click the folder Views and select Add | New Folder.
  2. Name the new folder. Provide the same name as the name of your controller, minus the suffix Controller (in our example: Spread).
  3. Right click the folder Spread, and select Add | New Item. The Add New Item dialog appears.
  4. Complete the following steps in the Add New Item dialog:
    1. Expand the Installed tab towards left, and select ASP.NET|MVC View Page.
    2. Set name of the view (for example: Index.cshtml).
    3. Click Add.
  5. Add the following code in Index.cshtml file.
    Index.cshtml
    Copy Code
    <script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            alert("Workbook Saved !!!");
        });
    </script>

Step 4: Build and Run the Project

  1. Click Build | Build Solution to build the project.
  2. Press F5 to run the project. Once you execute the project, you will notice that Workbook.xlsx file is created at projects root location.