# GC.Spread.Formatter.FormatterBase

## Content

# Class: FormatterBase

[Spread](../modules/GC.Spread).[Formatter](../modules/GC.Spread.Formatter).FormatterBase

## Table of contents

### Constructors

- [constructor](GC.Spread.Formatter.FormatterBase#constructor)

### Properties

- [typeName](GC.Spread.Formatter.FormatterBase#typename)

### Methods

- [format](GC.Spread.Formatter.FormatterBase#format)
- [fromJSON](GC.Spread.Formatter.FormatterBase#fromjson)
- [parse](GC.Spread.Formatter.FormatterBase#parse)
- [toJSON](GC.Spread.Formatter.FormatterBase#tojson)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new FormatterBase**(`format`, `cultureName`)

Represents a custom formatter with the specified format string.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `format` | `string` | The format. |
| `cultureName` | `string` | The culture name. |

## Properties

### <a id="typename" name="typename"></a> typeName

• **typeName**: `string`

Represents the type name string used for supporting serialization.

## Methods

### <a id="format" name="format"></a> format

▸ **format**(`obj`): `string`

Formats the specified object as a string with a conditional color. This function should be overwritten.

**`example`**
```
//This example creates a custom formatter.
var customFormatterTest = {};
customFormatterTest.prototype = GC.Spread.Formatter.FormatterBase;
customFormatterTest.format = function (obj, data) {
    data.conditionalForeColor = "blue";
    return "My format result : " + obj.toString();
};
customFormatterTest.parse = function (str) {
    if (!str) {
        return "";
    }
    return str;
}
activeSheet.getCell(1, 0).formatter(customFormatterTest);
activeSheet.getCell(1, 0).value("Test");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `Object` | The object with cell data to format. |

#### Returns

`string`

The formatted string.

___

### <a id="fromjson" name="fromjson"></a> fromJSON

▸ **fromJSON**(`settings`): `void`

Loads the object state from the specified JSON string.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `settings` | `Object` | The custom formatter data from deserialization. |

#### Returns

`void`

___

### <a id="parse" name="parse"></a> parse

▸ **parse**(`str`): `Object`

Parses the specified text. This function should be overwritten.

**`example`**
```
//This example creates a custom formatter.
var customFormatterTest = {};
customFormatterTest.prototype = GC.Spread.Formatter.FormatterBase;
customFormatterTest.format = function (obj, conditionalForeColor) {
    conditionalForeColor.value = "blue";
    return "My format result : " + obj.toString();
};
customFormatterTest.parse = function (str) {
    if (!str) {
        return "";
    }
    return str;
}
activeSheet.getCell(1, 0).formatter(customFormatterTest);
activeSheet.getCell(1, 0).value("Test")
```

#### Parameters

| Name | Type |
| :------ | :------ |
| `str` | `string` |

#### Returns

`Object`

The parsed object.

___

### <a id="tojson" name="tojson"></a> toJSON

▸ **toJSON**(): `Object`

Saves the object state to a JSON string.

#### Returns

`Object`

The custom formatter data.
