Interface IStyle
Represents a style description for a range. The Style object contains all style attributes (font, number format, alignment, and so on) as properties. There are several built-in styles, including Normal, Currency, and Percent. Using the Style object is a fast and efficient way to change several cell-formatting properties on multiple cells at the same time. For the Workbook object, the Style object is a member of the Styles collection. The Styles collection contains all the defined styles for the workbook
Inherited Members
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Base.dll
Syntax
public interface IStyle : IExtendedFormat, IParentApplication, IOptimizedUpdate
Properties
BuiltIn
Declaration
bool BuiltIn { get; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to check whether a IStyle is a built-in IStyle or not.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Check style built in
Console.WriteLine(workbook.Styles[6].BuiltIn);
Console.WriteLine(workbook.Styles[0].BuiltIn);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//False
//True
Interior
Returns interior object for this extended format.
Declaration
IInterior Interior { get; }
Property Value
Type |
---|
IInterior |
Examples
The following code illustrates how to access IStyle's interior object.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set interior
Syncfusion.XlsIO.Interfaces.IInterior interior = style.Interior;
//Set color
interior.ColorIndex = ExcelKnownColors.Red;
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
}
IsInitialized
Indicates whether IStyle is initialized (differs from Normal style). Read-only.
Declaration
bool IsInitialized { get; }
Property Value
Type |
---|
System.Boolean |
Examples
By default if the style is created using Add(String) method, then the style will be created based on the Normal style which is the default style. If the created style is modified then IsInitialized will be set to "true".
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Create style
IStyle style = workbook.Styles.Add("CustomStyle");
//Check style initialized or not
Console.WriteLine(style.IsInitialized);
//Set rich text
IRichTextString richText = worksheet["C2"].RichText;
//Set text
richText.Text = "Sample";
//Set font
IFont font = style.Font;
//Set color
font.Color = ExcelKnownColors.Red;
//Set rich text font
richText.SetFont(0, 5, font);
//Check style initialized or not
Console.Write(style.IsInitialized);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//False
//True
Name
Returns or sets the name of the IStyle object. Read-only String.
Declaration
string Name { get; }
Property Value
Type |
---|
System.String |
Examples
The following code illustrates how to access the name of the IStyle object.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Check style name
Console.WriteLine(workbook.Styles[6].Name);
Console.WriteLine(workbook.Styles[0].Name);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//CustomStyle
//Normal