Next we will format the content using styles. The code in this step should be added after the code from Step 2 of 4 within the Form_Load event.
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
'Add style 1. Dim style1 As New XLStyle(C1XLBook1) style1.Font = New Font("Tahoma", 9, FontStyle.Bold) style1.ForeColor = Color.RoyalBlue ' Add style 2. Dim style2 As New XLStyle(C1XLBook1) style2.Font = New Font("Tahoma", 9, FontStyle.Italic) style2.BackColor = Color.RoyalBlue style2.ForeColor = Color.White |
To write code in C#
Title Text |
Copy Code
|
---|---|
// Add style 1. XLStyle style1 = new XLStyle(c1XLBook1); style1.Font = new Font("Tahoma", 9, FontStyle.Bold); style1.ForeColor = Color.RoyalBlue; // Add style 2. XLStyle style2 = new XLStyle(c1XLBook1); style2.Font = new Font("Tahoma", 9, FontStyle.Italic); style2.BackColor = Color.RoyalBlue; style2.ForeColor = Color.White; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
For i = 0 To 9 ' Apply styles to the content. If (i + 1) Mod 2 = 0 Then sheet(i, 0).Style = style2 sheet(i, 1).Style = style1 sheet(i, 2).Style = style2 Else sheet(i, 0).Style = style1 sheet(i, 1).Style = style2 sheet(i, 2).Style = style1 End If Next i |
To write code in C#
C# |
Copy Code
|
---|---|
for (i = 0; i <= 9; i++) { // Apply styles to the content. if ((i + 1) % 2 == 0) { sheet[i, 0].Style = style2; sheet[i, 1].Style = style1; sheet[i, 2].Style = style2; } else { sheet[i, 0].Style = style1; sheet[i, 1].Style = style2; sheet[i, 2].Style = style1; } } |