Interface INumberFormat
Represents settings of number format.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Base.dll
Syntax
public interface INumberFormat : IParentApplication
Properties
DecimalPlaces
Number of digits after "." sign in the first section of this number format. Read-only.
Declaration
int DecimalPlaces { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to access DecimalPlaces
property.
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"].Value = "1200.40";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set number format index
style.NumberFormat = "#,##0.00";
//Set number format settings
INumberFormat numberFormat = style.NumberFormatSettings;
//Check number format decimal places
Console.Write(numberFormat.DecimalPlaces);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//2
FormatString
Returns format string. Read-only.
Declaration
string FormatString { get; }
Property Value
Type | Description |
---|---|
System.String |
Examples
The following code illustrates how to access the FormatString
of the NumberFormat applied.
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"].Value = "1200.40";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set number format index
style.NumberFormat = "#,##0.00";
//Set number format settings
INumberFormat numberFormat = style.NumberFormatSettings;
//Check number format string
Console.Write(numberFormat.FormatString);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//#,##0.00
FormatType
Returns format type of the first section of this number format. Read-only.
Declaration
ExcelFormatType FormatType { get; }
Property Value
Type | Description |
---|---|
ExcelFormatType |
Examples
The following code illustrates how to access the FormatType
of the NumberFormat applied.
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"].Value = "1200.40";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set number format index
style.NumberFormat = "#,##0.00";
//Set number format settings
INumberFormat numberFormat = style.NumberFormatSettings;
//Check number format type
Console.Write(numberFormat.FormatType);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//Number
Index
Returns format index. Read-only.
Declaration
int Index { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to access the Index
of the NumberFormat applied.
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"].Value = "1200.40";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set number format index
style.NumberFormat = "#,##0";
//Set number format settings
INumberFormat numberFormat = style.NumberFormatSettings;
//Get number format index
Console.Write(numberFormat.Index);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//3
IsFraction
Indicates whether the first section of this number format contains fraction sign. Read-only.
Declaration
bool IsFraction { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Examples
The following code illustrates how to access IsFraction
property.
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"].Value = "1200.40";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set number format index
style.NumberFormat = "# ?/?";
//Set number format settings
INumberFormat numberFormat = style.NumberFormatSettings;
//Check number format is fraction
Console.Write(numberFormat.IsFraction);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//True
IsScientific
Indicates whether first section of this number format contains E/E+ or E- signs in format string. Read-only.
Declaration
bool IsScientific { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Examples
The following code illustrates how to access IsScientific
property.
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"].Value = "1200.40";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set number format index
style.NumberFormat = "#.##E+##";
//Set number format settings
INumberFormat numberFormat = style.NumberFormatSettings;
//Get number format index
Console.Write(numberFormat.IsScientific);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//True
IsThousandSeparator
Indicates whether thousand separator is present in the first section of this number format. Read-only.
Declaration
bool IsThousandSeparator { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Examples
The following code illustrates how to access IsThousandOperator
property.
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"].Value = "1200.40";
//Add style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set style
worksheet["C2"].CellStyle = style;
//Set number format index
style.NumberFormat = "#,##0";
//Set number format settings
INumberFormat numberFormat = style.NumberFormatSettings;
//Check number format thousand separator
Console.Write(numberFormat.IsThousandSeparator);
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//True