Follow these steps to create a simple Console Application which demonstrates the SpreadsheetGear 2017 Core Engine.
Create a new Console Application
-
Launch Visual Studio 2008, Visual Studio 2010, Visual Studio 2012, Visual Studio 2013, Visual Studio 2015 or Visual Studio 2017.
-
On the File menu, point to New and click Project. The New Project dialog box appears.
-
Under Project Types / Templates, choose Visual C# -> Windows -> Console Application.
- Change the Name and Location as desired.
-
Click OK to create the project.
Add a reference to SpreadsheetGear 2017
- In Solution Explorer, select the project you just created.
- On the Project menu, click Add Reference. The Add Reference dialog box appears.
- In the Add Reference dialog box, click the .NET tab. A list of .NET components appears.
- In the list of .NET components, select SpreadsheetGear 2017 Core Engine and SpreadsheetGear 2017 GDI+ Drawing Library for use with .NET 4.0+, or select SpreadsheetGear 2017 for .NET 2.0 for use with .NET 2.0+.
- Click OK to add the reference.
Add code to create a workbook and calculate a value
-
In Solution Explorer, open the source file which contains the Main(...) method (the default is Program.cs).
-
Replace the Main() method with:
Simple Core Engine Sample
|
Copy Code
|
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
- Build menu, click
- Build Solution. The solution builds with no errors.
-
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.