# Allow Invalid Formulas

## Content

**SpreadJS** supports marking cells in which the cell value is an invalid formula string. The InvalidFormula cell state can apply a style to a cell with a string value that matches the invalid formula.
![allow-invalid-formula-pic.png](https://gcdocumentsitekrblob.blob.core.windows.net/document-site-files/images/8d606653-16a0-474d-b9dc-e2b4d01c2446/allow-invalid-formula-pic.fd076e.png)

The **[CellStatesType](https://developer.mescius.com/spreadjs/api/enums/GC.Spread.Sheets.CellStatesType)** enumeration provides the **[invalidFormula](https://developer.mescius.com/spreadjs/api/enums/GC.Spread.Sheets.CellStatesType#invalidformula)** option to indicate that the cell value is an invalid formula string. You can also show whether the sheet allows an input invalid formula string. For this purpose, the **[GC.Spread.Sheets.IWorkbookOptions](https://developer.mescius.com/spreadjs/api/interfaces/GC.Spread.Sheets.IWorkbookOptions)** interface provides the **[allowInvalidFormula](https://developer.mescius.com/spreadjs/api/interfaces/GC.Spread.Sheets.IWorkbookOptions#allowinvalidformula)** option. With this option, the user can input invalid formula in the editor directly, and the worksheet will keep it as a string. The default value for this option is false.

The code implementation below depicts setting an invalid formula state for a cell value:

```JavaScript
spread.options.allowInvalidFormula = true;
var style = new GC.Spread.Sheets.Style();
var wholeRange = new GC.Spread.Sheets.Range(0, 0, sheet.getRowCount(), sheet.getColumnCount());
var borderTop = new GC.Spread.Sheets.LineBorder('red', GC.Spread.Sheets.LineStyle.mediumDashed);
var borderBottom = new GC.Spread.Sheets.LineBorder('red', GC.Spread.Sheets.LineStyle.mediumDashed);
var borderLeft = new GC.Spread.Sheets.LineBorder('red', GC.Spread.Sheets.LineStyle.mediumDashed);
var borderRight = new GC.Spread.Sheets.LineBorder('red', GC.Spread.Sheets.LineStyle.mediumDashed);
style.borderTop = borderTop;
style.borderBottom = borderBottom;
style.borderLeft = borderLeft;
style.borderRight = borderRight;
sheet.cellStates.add(wholeRange, GC.Spread.Sheets.CellStatesType.invalidFormula, style, GC.Spread.Sheets.SheetArea.viewport);
```

If two or more states intersect, the last set style takes priority and will compose with the other style. The priority of cell states is as follows:
edit > hover > active > selected > invalid formula > dirty > invalid > readonly