Adding Content to a Workbook

To create a new workbook and add values to the first ten cells, complete the following steps:

  1. Double-click the C1XLBook component in the Toolbox to add it to your form.
  2. Add values to the first ten cells:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim sheet As XLSheet = C1XLBook1.Sheets(0)
    Dim i As Integer
      For i = 0 To 9
        sheet(i,0).Value = i + 1
      Next i
    

    To write code in C#

    C#
    Copy Code
    XLSheet sheet = c1XLBook1.Sheets[0]; 
    for (int i = 0; i <= 9; i++)
            { 
            sheet[i,0].Value = i + 1; 
            }
    
  3. Save and open the book:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    C1XLBook1.Save("c:\mybook.xls")
    System.Diagnostics.Process.Start("C:\mybook.xls")

    To write code in C#

    C#
    Copy Code
    c1XLBook1.Save(@"c:\mybook.xls");
    System.Diagnostics.Process.Start(@"C:\mybook.xls");