📗 SheetJS Community Edition -- Spreadsheet Data Toolkit
Go to file
2017-03-21 03:50:08 -04:00
bin flow typing and cleanup 2017-03-12 03:34:36 -04:00
bits version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
misc version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
test version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
.flowconfig flow typing and cleanup 2017-03-12 03:34:36 -04:00
.gitignore version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
.jscs.json version bump 0.7.1: performance 2014-06-04 20:14:59 -04:00
.npmignore version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
.travis.yml flow typing and cleanup 2017-03-12 03:34:36 -04:00
index.html version bump 0.6.5: eliminating bad idioms 2014-04-25 11:22:36 -07:00
LICENSE flow typing and cleanup 2017-03-12 03:34:36 -04:00
Makefile version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
package.json version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
README.md version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
ssf.flow.js version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
ssf.js version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00
ssf.md version bump 0.9.0: is_date helper 2017-03-21 03:50:08 -04:00

SSF

ssf (SpreadSheet Format) is a pure-JS library to format data using ECMA-376 spreadsheet format codes (used in popular spreadsheet software packages).

Installation

With npm:

$ npm install ssf

In the browser:

<script src="ssf.js"></script>

The browser exposes a variable SSF

When installed globally, npm installs a script ssf that renders the format string with the given arguments. Running the script with -h displays help.

The script will manipulate module.exports if available (e.g. in a CommonJS require context). This is not always desirable. To prevent the behavior, define DO_NOT_EXPORT_SSF.

Usage

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.

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)

SSF.get_table() gets the internal format table (number to format mapping).

SSF.load_table(table) sets the internal format table.

Other Utilities

SSF.parse_date_code(val:number, opts:?any) parses val, returning an object:

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 */

  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 */
}

SSF.is_date(fmt:string):boolean returns true if fmt encodes a date format.

License

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.

References

  • [ECMA-376] Office Open XML File Formats
  • [MS-XLSB] Excel (.xlsb) Binary File Format

Badges

Sauce Test Status

Build Status

Coverage Status

NPM Downloads

Dependencies Status

ghit.me

Analytics