Excel.NumberFormatInfo class

Defines the culturally appropriate format of displaying numbers. This is based on current system culture settings.

Extends

Remarks

[ API set: ExcelApi 1.11 ]

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

numberDecimalSeparator

Gets the string used as the decimal separator for numeric values. This is based on current system settings.

numberGroupSeparator

Gets the string used to separate groups of digits to the left of the decimal for numeric values. This is based on current system settings.

Methods

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.NumberFormatInfo object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.NumberFormatInfoData) that contains shallow copies of any loaded child properties from the original object.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

numberDecimalSeparator

Gets the string used as the decimal separator for numeric values. This is based on current system settings.

readonly numberDecimalSeparator: string;

Property Value

string

Remarks

[ API set: ExcelApi 1.11 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/50-workbook/culture-info.yaml

// This will convert a number like "14,37" to "14.37"
// (assuming the system decimal separator is ".").
  await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const decimalSource = sheet.getRange("B2");
decimalSource.load("values");
context.application.cultureInfo.numberFormat.load("numberDecimalSeparator");
await context.sync();

const systemDecimalSeparator = context.application.cultureInfo.numberFormat.numberDecimalSeparator;
const oldDecimalString: string = decimalSource.values[0][0];

// This assumes the input column is standardized to use "," as the decimal separator. 
const newDecimalString = oldDecimalString.replace(",", systemDecimalSeparator);

const resultRange = sheet.getRange("C2");
resultRange.values = [[newDecimalString]];
resultRange.format.autofitColumns();
await context.sync();
  });

numberGroupSeparator

Gets the string used to separate groups of digits to the left of the decimal for numeric values. This is based on current system settings.

readonly numberGroupSeparator: string;

Property Value

string

Remarks

[ API set: ExcelApi 1.11 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/50-workbook/culture-info.yaml

await Excel.run(async (context) => {
  // This will convert a number like "123-456-789" to "123,456,789"
  // (assuming the system thousands separator is ",").
  const sheet = context.workbook.worksheets.getItem("Sample");
  const bigNumberSource = sheet.getRange("B3");
  bigNumberSource.load("values");
  context.application.cultureInfo.numberFormat.load("numberGroupSeparator");
  await context.sync();

  const systemThousandsSeparator = context.application.cultureInfo.numberFormat.numberGroupSeparator;
  const oldBigNumberString: string = bigNumberSource.values[0][0];
  
  // This assumes the input column is standardized to use "-" as the number group separator. 
  const newBigNumberString = oldBigNumberString.replace(/-/g, systemThousandsSeparator);

  const resultRange = sheet.getRange("C3");
  resultRange.values = [[newBigNumberString]];
  resultRange.format.autofitColumns();
  await context.sync();
});

Method Details

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: Excel.Interfaces.NumberFormatInfoLoadOptions): Excel.NumberFormatInfo;

Parameters

options
Excel.Interfaces.NumberFormatInfoLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.NumberFormatInfo;

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.NumberFormatInfo;

Parameters

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.NumberFormatInfo object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.NumberFormatInfoData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.NumberFormatInfoData;

Returns