ComponentOne Excel for .NET
In This Topic
    Formatting Cells
    In This Topic

    To format the cells of a book, complete the following steps:

    1. Double-click the C1XLBook component in the Toolbox to add it to your form.
    2. Create a new style and assign the style some properties:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Dim style1 As New XLStyle(C1XLBook1)
      style1.ForeColor = Color.Gold
      style1.BackColor = Color.Blue
      style1.Format = "$  .00"
      

      To write code in C#

      C#
      Copy Code
      XLStyle style1 = new XLStyle(c1XLBook1);
      style1.ForeColor = Color.Gold;
      style1.BackColor = Color.Blue;
      style1.Format = "$ .00";
      
    3. Add some content and apply the style to the cells in the first column of the sheet:

      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
              sheet(i, 0).Style = style1
      Next i
      

      To write code in C#

      C#
      Copy Code
      C1.C1Excel.XLSheet sheet = c1XLBook1.Sheets[0];
      int i;
      for (i = 0; i <= 9; i++)
              { 
               sheet[i,0].Value = i + 1;
               sheet[i, 0].Style = style1;
              }
      
    4. 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");