Excel for WPF | ComponentOne
C1Excel Task-Based Help / Adding Content to a Workbook
In This Topic
    Adding Content to a Workbook
    In This Topic

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

    1. Add a reference to C1.WPF.Excel.dll or C1.Silverlight.Excel.dll and create a C1XLBook.

      C#
      Copy Code
      // Create a new workbook to be saved
       C1XLBook book = new C1XLBook();
      
    2. Add values to the first ten cells.

      C#
      Copy Code
      // write content for the first ten cells
      XLSheet sheet = book.Sheets[0];
        for (int i = 0; i <= 9; i++)
         {
          sheet[i, 0].Value = i + 1;
         }
      
    3. Save and open the workbook. The code looks like the following.

      C#
      Copy Code
      // Save and open the file
      book.Save(@"C:\test.xls");
      System.Diagnostics.Process.Start(@"C:\test.xls");
      

      Excel File Output