Spread.Sheets Documentation > Developer's Guide > Managing Data > Formatting Cells |
You can format cell values using standard number, date time, and custom formats. You can also set the culture to "ja-jp" or "en-us".
Numbers are formatted based on the current culture. The default culture is English. You can set the culture to "ja-jp" or "en-us". You can specify the culture for the widget or individual cells. The cell culture does not change the widget culture.
Spread.Sheets supports common fraction formats, such as "# ?/?", "# ??/??", "# ?/4", and "#,## ?/?". You can convert a negative value to a fraction. Spread.Sheets also supports the local ID "$-411" and DBNumber.
The custom format mode supports the combo, conditional, and forecolor formatters. The "(", ")", and "*" expressions are not supported.
You can also create a custom formatter with the FormatterBase class.
For more information on number format codes, refer to http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx.
This example formats cell values.
JavaScript |
Copy Code
|
---|---|
var dvalue= 12345.6789; activeSheet.setValue(0,0,dvalue); activeSheet.getCell(0, 1).formatter("M"); activeSheet.setValue(0, 1, new Date(2011, 2, 9)); activeSheet.getCell(0, 2).formatter("m"); activeSheet.setValue(0, 2, new Date(2012, 10, 15)); activeSheet.getCell(0, 3).formatter("General"); activeSheet.setValue(0, 3, new Date(2012, 10, 15)); activeSheet.getCell(0, 4).formatter("#.#%"); activeSheet.setValue(0, 4, 1); activeSheet.getCell(1, 0).formatter("[>2]0.0;[<-3]0.0;zero;"); activeSheet.setValue(1, 0, 3); |
This example formats a cell value as a fraction.
JavaScript |
Copy Code
|
---|---|
var dvalue= 123.89; activeSheet.setValue(0,0,dvalue); activeSheet.getCell(0, 0).formatter("# ??/??"); |
This example formats a cell value using locale ID "$-411".
JavaScript |
Copy Code
|
---|---|
var dvalue= 123.89; activeSheet.setValue(0,0,dvalue); activeSheet.getCell(0,0).formatter("[$-411]dddd"); |
This example formats a cell value using DBNumber.
JavaScript |
Copy Code
|
---|---|
var dvalue= 123.89; activeSheet.setValue(0,0,dvalue); activeSheet.getCell(0,0).formatter("[DBNum2][$-411]General"); |
This example sets the culture for the widget.
JavaScript |
Copy Code
|
---|---|
//widget setting GC.Spread.Common.CultureManager.culture("ja-jp"); |
This example sets the culture for the cell.
JavaScript |
Copy Code
|
---|---|
//cell setting //Input date string "2014/01/07" in cell[0,0] and cell[0,1] activeSheet.getCell(0,0).formatter(new GC.Spread.Formatter.GeneralFormatter("yyyy/MM/dd dddd", "ja-jp")); activeSheet.getCell(0,1).formatter(new GC.Spread.Formatter.GeneralFormatter("yyyy/MM/dd dddd", "en-us")); |