Other API Samples C# logo

Create Style SpreadsheetGear API Sample

Description

Create a custom style when you have a common cell format that could be applied to many cells in a workbook.

Sample Source Code

// Create a new workbook.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["Sheet1"];
SpreadsheetGear.IRange cells = worksheet.Cells;

// Create a new Style and call it "My Style".
SpreadsheetGear.IStyle style = workbook.Styles.Add("Inverted");
style.Font.Color = SpreadsheetGear.Colors.White;
style.Interior.Color = SpreadsheetGear.Colors.Black;

// Add some cell data to A1:A10.
cells["A1:A10"].Value = "Hello World!";

// Apply custom style to A6:A10
cells["A6:A10"].Style = style;

worksheet.UsedRange.EntireColumn.AutoFit();