SpreadsheetGear 2017
SpreadsheetGear 2017 > Tutorials > Silverlight

Follow these steps to use SpreadsheetGear 2017 for Silverlight in a Silverlight Project

Create a new Silverlight 5 Project

  1. Launch Visual Studio 2010, Visual Studio 2012, Visual Studio 2013 or Visual Studio 2015. Visual Studio 2017 does not support Silverlight.
  2. On the File menu, point to New and click Project.  The New Project dialog box appears.
  3. Under Installed Templates, choose Visual C#.
  4. Under Visual C#, choose Silverlight Application.
  5. Change the Name and Location as desired.
  6. Click OK to proceed to the New Silverlight Application dialog box.
  7. Uncheck the Host the Silverlight application in a new Web site checkbox.
  8. Under Options, set the Silverlight Version to Version 5.
  9. Click OK to create the project.

Create a Window with a Workbook and a Button

  1. Open the SpreadsheetGear 2017 category in the Visual Studio Toolbox.
  2. Click and drag WorkbookView onto MainPage.xaml.
  3. In Visual Studio 2012, Visual Studio 2013 and Visual Studio 2015 you will need to give the new WorkbookView instance the name 'workbookView1' by selecting the WorkbookView, pressing F4 for Properties, and changing the Name property from <No Name> to 'workbookView1'.
  4. Open the Common Silverlight Controls category in the Toolbox.
  5. Click and drag a Button onto MainPage.xaml.
  6. Adjust the size of MainPage.xaml 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.

    Simple Windows Forms Sample

    Copy Code
    // Interrupt background calculation if necessary and acquire a lock on the workbook set.
        // 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;
        // Release the lock on the workbook set.

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 2017

  1. Close the application if you have not already done so.
  2. Select the MainPage.xaml (Design) tab in Visual Studio.
  3. Right click on the WorkbookView control on MainPage.xaml 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 in the Workbook Designer.
  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.