Skip to main content

setFormat()

Description

Sets a specified format to the value of a cell

Usage

setFormat(cell: string, format: string | array): void;

Parameters

  • cell - (required) the id(s) of a cell(s) or a range of cells
  • format - (required) the name(s) of the number format to apply to cells value

Example

const spreadsheet = new dhx.Spreadsheet("spreadsheet", {});
spreadsheet.parse(data);

// applies the currency format to the cell A1
spreadsheet.setFormat("A1","currency");
info

Starting with v4.1, the reference to a cell can be specified in the following format:

spreadsheet.setFormat("sheet1!A2", "number"); 

where sheet1 is the name of the tab.

In case the name of the tab isn't specified, the method will set the format to the value of a cell of the active tab.

Related articles: Number formatting