0.11.2 • Published 4 years ago

ssf v0.11.2

Weekly downloads
1,158,901
License
Apache-2.0
Repository
github
Last release
4 years ago

SheetJS SSF

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

This is the community version. We also offer a pro version with additional features like international support as well as dedicated support.

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 . 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. 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 NameDefaultDescription
date1904falseUse 1904 date system if true, 1900 system if false

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.

Examples

Related Packages

ssf-cli is a simple NodeJS command line tool for formatting numbers.

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-XLS: Excel Binary File Format (.xls) Structure Specification
  • MS-XLSB: Excel (.xlsb) Binary File Format

Badges

Sauce Test Status

Build Status

Coverage Status

NPM Downloads

Dependencies Status

Analytics

xlsxddc-xlsx-stylejsexcelstyleexcelstylewcd-xlsx@rowsncolumns/spreadsheetxlstream_copyivops-xlsx-style@darrinholst/xlsx@bwells78/xlsx-stylecd-xlsx-stylexlsx-style-branchhybo-xlsx-style-giteefixed-xlsx-styledz-xlsx-style-fixbravo-utilsxlsx-style-new@infinitebrahmanuniverse/nolb-ssf@everything-registry/sub-chunk-2815nora-xlsx-style@amblade/patswap-default-token-list@algonomia/xlsx@datahu/core@bkief29/xlsx@bshevlin/xlsx@blws/xlsx@balderdash/xlsx@cael-aero/casa-utils@cael-aero/gfa-utils@geoblink/xlsxzyf-xlsx-stylexj-xlsx-stylexlsx-style-spartaxlsx-style-syfxlsx-style-tgfxlsx-style-twxlsx-style-typoxlsx-style-uxlsx-style-updatexlsx-style-vitexlsx-style-vuexlsx-style-vue3xlsx-style-wangxjxlsx-style-wuxlsx-style-ycxlsx-style2xlsx-styleablexlsx-styledxlsx-style-kimxlsx-style-leapxlsx-style-luleiyuxlsx-style-lw-etcxlsx-style-lxxlsx-style-medalsoftxlsx-style-nextxlsx-style-perfectxlsx-style-plusxlsx-style-privatexlsx-style-proxlsx-style-qianxlsx-style-relayxlsx-style-revisexlsx-style-revisionxlsx-style-rowsxlsx-style-scxlsx-style-soundaixlsx-style-bug-fix-vitexlsx-style-bug-fix-vite1xlsx-style-clixlsx-style-compsxlsx-style-correctxlsx-style-cpexcelxlsx-style-cpexcel-mobingixlsx-style-cptablexlsx-style-customxlsx-style-d807xlsx-style-ebizxlsx-style-enadle-change-rowheightxlsx-style-exxlsx-style-exportxlsx-style-extendxlsx-style-fixxlsx-style-fix-modulexlsx-style-fixedxlsx-style-fixed-tyxlsx-style-fixed-zhouxlsx-style-fixedverxlsx-style-formulaxlsx-style-haoxlsx-style-heightxlsx-style-hwxlsx-style-hxlxlsx-style-hzxxlsx-style-ivopsxlsx-style-jeecgxlsx-style-jszip3xlsx-style-jszip3-fixxlsx-style-jszip3.7xlsx-proxlsx-r
0.11.2

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.3

4 years ago

0.10.2

6 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.2

10 years ago

0.8.1

10 years ago

0.8.0

10 years ago

0.7.1

10 years ago

0.7.0

10 years ago

0.6.5

10 years ago

0.6.4

10 years ago

0.6.3

10 years ago

0.6.2

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.11

10 years ago

0.5.10

10 years ago

0.5.9

10 years ago

0.5.8

10 years ago

0.5.7

10 years ago

0.5.6

10 years ago

0.5.5

10 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.0.3

10 years ago

0.0.2

11 years ago

0.0.1

11 years ago