SpreadsheetGear The Performance Spreadsheet Component Company 
Getting Started

Using SpreadsheetGear for .NET 2007 in a Visual Studio 2005 / 2008 Project
 

See the Introduction for a brief overview of SpreadsheetGear for .NET 2007.

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

This Getting Started section pertains to Windows Forms applications. The SpreadsheetGear Explorer solutions provide C# and Visual Basic samples which demonstrate the most commonly used SporeadsheetGear for .NET features and API's. For ASP.NET applications, the SpreadsheetGear Web site provides many Excel Reporting, Excel Charting, Excel to DataGrid and Excel Calculation samples which work with ASP.NET 1.1, ASP.NET 2.0 and ASP.NET 3.0.

 

Create a new Windows Application Project

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

 

Create a Window with a Workbook and a Button

  1. Open the SpreadsheetGear category in the Visual Studio Toolbox.
  2. Click and drag WorkbookView onto Form1.
  3. Open the Common Controls category in the Toolbox.
  4. Click and drag a Button onto Form1.
  5. Adjust the size of Form1 and the controls as desired.

 

Add Code to Calculate a Value and Display it in a Cell

  1. Double click the Button to display the Button's Click event handler.
  2. Copy the following code to the Button's Click event handler.

            // Interrupt background calculation if necessary and acquire a lock on the workbook set.
            workbookView1.GetLock();

            try
            {
                // Get a reference to the active cell.
                SpreadsheetGear.IRange activeCell = workbookView1.ActiveCell;

                // Set a formula
                activeCell.Formula = "=24901.55 / PI()";

                // Place the result of the formula in cell B2.
                SpreadsheetGear.IRange b2 = workbookView1.ActiveWorksheet.Cells["B2"];
                b2.Value = "The diameter of the earth is " + activeCell.Text + " miles.";
               
                // Set the font of B2 to italic.
                b2.Font.Italic = true;
            }
            finally
            {
                // Release the lock on the workbook set.
                workbookView1.ReleaseLock();
            }


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 window and when you click the Button, cell B2 will display "The diameter of the earth is 7926.409546 miles."

 

Explore SpreadsheetGear for .NET 2007

  1. Close the application if you have not already done so.
  2. Select the Form1.cs (Design) tab in Visual Studio.
  3. Right click on the WorkbookView control on Form1 and click Workbook Designer.
  4. Enter values and formulas in cells in the Workbook Designer.
  5. On the Format menu, click Cells... to bring up the Range Explorer which is a modeless dialog used to format cells. Notice that changes made in the Range Explorer are displayed immediately.
  6. Right click on the workbook in the Workbook Designer and click Workbook Explorer. Use the Workbook Explorer to add, remove and save workbooks as well as add, delete, rename, copy and move worksheets. Right click on each element in the tree on the left to see a menu of available actions.
  7. Close the Workbook Designer and notice that any changes you made in the Workbook Designer are reflected in the WorkbookView control in Visual Studio.
  8. From Visual Studio, Press F5 to launch the application. Notice that the changes made in the Workbook Designer are saved with the form and loaded at run time.
  9. Right click on the WorkbookView and click Workbook Designer. The Workbook Designer, Workbook Explorer and Range Explorer are available at runtime to applications which are powered by SpreadsheetGear for .NET.