| 
									
										
										
										
											2017-04-30 04:54:41 +00:00
										 |  |  | # [SheetJS SSF](http://sheetjs.com)
 | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 03:35:31 +00:00
										 |  |  | ssf (SpreadSheet Format) is a pure JS library to format data using ECMA-376 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | spreadsheet format codes (used in popular spreadsheet software packages). | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | ## Installation
 | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | With [npm](https://www.npmjs.org/package/ssf): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```bash | 
					
						
							|  |  |  | $ npm install ssf | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | In the browser: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | ```html | 
					
						
							|  |  |  | <script src="ssf.js"></script> | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | The browser exposes a variable `SSF` | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | When installed globally, npm installs a script `ssf` that renders the format | 
					
						
							|  |  |  | string with the given arguments.  Running the script with `-h` displays help. | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 03:35:31 +00:00
										 |  |  | The script will manipulate `module.exports` if available .  This is not always | 
					
						
							|  |  |  | desirable.  To prevent the behavior, define `DO_NOT_EXPORT_SSF`. | 
					
						
							| 
									
										
										
										
											2014-01-10 19:09:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | ## Usage
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 20:24:37 +00:00
										 |  |  | `SSF.format(fmt, val, opts)` formats `val` using the format `fmt`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If `fmt` is a string, it will be parsed and evaluated.  If `fmt` is a `number`, | 
					
						
							|  |  |  | the actual format will be the corresponding entry in the internal format table. | 
					
						
							|  |  |  | For a raw numeric format like `000`, the value should be passed as a string. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Date arguments are interpreted in the local time of the JS client. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The options argument may contain the following keys: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | | Option Name | Default | Description                                          | | 
					
						
							|  |  |  | | :---------- | :-----: | :--------------------------------------------------- | | 
					
						
							| 
									
										
										
										
											2018-02-21 03:35:31 +00:00
										 |  |  | | `date1904`  | false   | Use 1904 date system if true, 1900 system if false   | | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ### Manipulating the Internal Format Table
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Binary spreadsheet formats store cell formats in a table and reference by index. | 
					
						
							|  |  |  | This library uses a global table: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | `SSF._table` is the underlying object, mapping numeric keys to format strings. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | `SSF.load(fmt:string, idx:?number):number` assigns the format to the specified | 
					
						
							|  |  |  | index and returns the index.  If the index is not specified, SSF will search the | 
					
						
							|  |  |  | space for an available format slot pick an unused slot.  For compatibility with | 
					
						
							|  |  |  | the XLS and XLSB file formats, custom indices should be in the valid ranges | 
					
						
							|  |  |  | `5-8`, `23-26`, `41-44`, `63-66`, `164-382` (see `[MS-XLSB] 2.4.655 BrtFmt`) | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | `SSF.get_table()` gets the internal format table (number to format mapping). | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | `SSF.load_table(table)` sets the internal format table. | 
					
						
							| 
									
										
										
										
											2014-01-10 19:09:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | ### Other Utilities
 | 
					
						
							| 
									
										
										
										
											2014-01-10 19:09:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | `SSF.parse_date_code(val:number, opts:?any)` parses `val`, returning an object: | 
					
						
							| 
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | ```typescript | 
					
						
							|  |  |  | type SSFDate = { | 
					
						
							|  |  |  |   D:number; /* number of whole days since relevant epoch, 0 <= D */ | 
					
						
							|  |  |  |   y:number; /* integral year portion, epoch_year <= y */ | 
					
						
							|  |  |  |   m:number; /* integral month portion, 1 <= m <= 12 */ | 
					
						
							|  |  |  |   d:number; /* integral day portion, subject to gregorian YMD constraints */ | 
					
						
							|  |  |  |   q:number; /* integral day of week (0=Sunday .. 6=Saturday) 0 <= q <= 6 */ | 
					
						
							| 
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  |   T:number; /* number of seconds since midnight, 0 <= T < 86400 */ | 
					
						
							|  |  |  |   H:number; /* integral number of hours since midnight, 0 <= H < 24 */ | 
					
						
							|  |  |  |   M:number; /* integral number of minutes since the last hour, 0 <= M < 60 */ | 
					
						
							|  |  |  |   S:number; /* integral number of seconds since the last minute, 0 <= S < 60 */ | 
					
						
							|  |  |  |   u:number; /* sub-second part of time, 0 <= u < 1 */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-21 07:45:12 +00:00
										 |  |  | `SSF.is_date(fmt:string):boolean` returns `true` if `fmt` encodes a date format. | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 16:39:12 +00:00
										 |  |  | ## Examples
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - [Basic Demo](http://oss.sheetjs.com/ssf/) | 
					
						
							|  |  |  | - [Custom Formats Builder](https://customformats.com) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-06 16:49:25 +00:00
										 |  |  | ## License
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | Please consult the attached LICENSE file for details.  All rights not explicitly | 
					
						
							|  |  |  | granted by the Apache 2.0 license are reserved by the Original Author. | 
					
						
							| 
									
										
										
										
											2014-01-10 19:09:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | ## References
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 03:35:31 +00:00
										 |  |  |  - `ECMA-376`: Office Open XML File Formats | 
					
						
							|  |  |  |  - `MS-XLS`: Excel Binary File Format (.xls) Structure Specification | 
					
						
							|  |  |  |  - `MS-XLSB`: Excel (.xlsb) Binary File Format | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Badges
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [](https://saucelabs.com/u/ssfjs) | 
					
						
							| 
									
										
										
										
											2014-01-10 19:09:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 00:07:30 +00:00
										 |  |  | [](https://travis-ci.org/SheetJS/ssf) | 
					
						
							| 
									
										
										
										
											2014-01-10 19:09:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | [](https://coveralls.io/r/SheetJS/ssf?branch=master) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [](https://npmjs.org/package/ssf) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [](https://david-dm.org/sheetjs/ssf) | 
					
						
							| 
									
										
										
										
											2014-02-17 09:28:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | [](https://ghit.me/repo/sheetjs/js-xlsx) | 
					
						
							| 
									
										
										
										
											2014-01-10 19:09:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | [](https://github.com/SheetJS/ssf) |