SpreadsheetGear The Performance Spreadsheet Component Company 

Getting Started

Using SpreadsheetGear for .NET in a Visual Studio.NET Project

 

For the latest FAQ's, how-to's, documentation, samples, support options and new versions please visit www.spreadsheetgear.com.

 

This getting started section assumes that you have successfully installed SpreadsheetGear for .NET and that you are running Visual Studio.NET 2003 or Visual Studio.NET 2005.

 

Create a new Console Application Project

  1. Launch Visual Studio .NET.
  2. On the File menu, point to New and click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual C# Projects in Visual Studio.NET 2003, or Visual C# in Visual Studio.NET 2005.
  4. Under Templates, click Console Application.
  5. Change the Name and Location as desired.
  6. Click OK to create the project.

 

Add a reference to SpreadsheetGear for .NET

  1. In Solution Explorer, select the project you just created.
  2. On the Project menu, click Add Reference. The Add Reference dialog box appears.
  3. In the Add Reference dialog box, click the .NET tab. A list of .NET components appears.
  4. In the list of .NET components, click SpreadsheetGear.
  5. If using Visual Studio.NET 2003, click Select to add SpreadsheetGear to the Selected Components list.
  6. Click OK to add the reference.

 

Add code to create a workbook and calculate a value

  1. In Solution Explorer, open the source file which contains the Main(...) method (the default is Class1.cs in Visual Studio.NET 2003 or Program.cs in Visual Studio.NET 2005).
  2. Replace the Main() method with:

static void Main(string[] args)

{

// 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. On the Build menu, click Build Solution. The solution builds with no errors.
  2. On the Debug menu, click Start Without Debugging. The application runs in a console window and displays:

The diameter of the earth is 7926.40954629997 miles.

 

 


See our live Excel Reporting, Excel Charting, Excel to DataGrid and Excel Calculation Samples.

Copyright © 2003-2007 SpreadsheetGear LLC. All Rights Reserved.

SpreadsheetGear and Spreadsheet Gear are trademarks of SpreadsheetGear LLC.