Back To .NET Standard Tutorials

SpreadsheetGear Engine for .NET Tutorials

Console App - Spreadsheet Calculations using Visual Studio for Windows

Follow these steps to create a simple Console App with Visual Studio Code for Windows that utilizes SpreadsheetGear Engine for .NET to perform a basic formula calculation. Note that you can target either the full .NET Framework or .NET Core with this tutorial.

Create a new Console Application

  1. Launch Visual Studio 2015 or later.
  2. On the File menu, navigate to New → Project...
  3. Under Project Types / Templates, choose either:
    • Visual C# → Windows → Console Application, which will target the full .NET Framework.
    • Visual C# → .NET Core → Console App (.NET Core), which will target .NET Core.
  4. Change the Name and Location as desired.
  5. Click OK to create the project.

Add SpreadsheetGear Engine for .NET to your project

  1. On the Project menu, click Manage NuGet Packages. The NuGet Package Manager window appears.
  2. In the NuGet Package Manager window, click the Browse tab and enter "SpreadsheetGear" in the search field.
  3. In the list of NuGet packages, select "SpreadsheetGear" and click Install.
  4. You might be prompted to confirm this change to your project. Click OK.
  5. You will be prompted to accept SpreadsheetGear's License Agreement. Click I Accept if you wish to proceed.
  6. Visual Studio should begin the installation process and add a reference to SpreadsheetGear in your Project's References folder.
  7. Close the NuGet Package Manager UI Tab.

Add code to create a workbook and calculate a value

This tutorial will work with the free version of SpreadsheetGear Engine for .NET (i.e., without activating SpreadsheetGear with your Signed License. Learn more about Signed Licenses here). If you wish to use the free version of SpreadsheetGear Engine for .NET, omit the first line in the source code below.

  1. If Program.cs is not already open, open it now from the Solution Explorer.
  2. Replace the contents of the Main(...) method with the following:
    static void Main(string[] args)
        // If desired, activate the trial or fully licensed version of SpreadsheetGear.
        SpreadsheetGear.Factory.SetSignedLicense("YOUR SIGNED LICENSE HERE");
        // Create a new empty workbook in a new workbook set.
        SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
        // Get a reference to the first worksheet.
        SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["Sheet1"];
        // Get a reference to the top left cell of Sheet1.
        SpreadsheetGear.IRange a1 = worksheet.Cells["A1"];
        // Set a formula.
        a1.Formula = "=24901.55 / PI()";
        // Output the result of the formula.
        Console.WriteLine("The diameter of the earth is " + a1.Value + " miles.");

Build and run the application

  1. From the Build menu, select Build Solution. The solution should build without errors.
  2. On the Debug menu, click Start Without Debugging.
  3. A Command Prompt Window should appear with the following output:
    The diameter of the earth is 7926.40954629997 miles.