Independentsoft
Home
Products
Purchase
Support
Downloads
Company
Contact
ODF .NET
>
Tutorial
> Set cell color
The following example shows you how to set cell background color and text color.
See screenshot
.
C# example
using System; using Independentsoft.Odf; using Independentsoft.Odf.Styles; namespace Sample { class Program { static void Main(string[] args) { Spreadsheet spreadsheet = new Spreadsheet(); CellStyle style1 = new CellStyle("CS1"); style1.CellProperties.BackgroundColor = System.Drawing.Color.Yellow; style1.TextProperties.Color = System.Drawing.Color.Red; spreadsheet.AutomaticStyles.Styles.Add(style1); Cell a1 = new Cell(100); a1.Style = "CS1"; Table sheet1 = new Table(); sheet1["A1"] = a1; spreadsheet.Tables.Add(sheet1); spreadsheet.Save("c:\\test.ods"); } } }
VB example
Imports System Imports Independentsoft.Odf Imports Independentsoft.Odf.Styles Module Module1 Sub Main(ByVal args() As String) Dim spreadsheet As New Spreadsheet() Dim style1 As New CellStyle("CS1") style1.CellProperties.BackgroundColor = System.Drawing.Color.Yellow style1.TextProperties.Color = System.Drawing.Color.Red spreadsheet.AutomaticStyles.Styles.Add(style1) Dim a1 As New Cell(100) a1.Style = "CS1" Dim sheet1 As New Table() sheet1("A1") = a1 spreadsheet.Tables.Add(sheet1) spreadsheet.Save("c:\test.ods") End Sub End Module