How to use the ssf.format function in ssf

To help you get started, we’ve selected a few ssf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lambrojos / supersalmon / lib / worksheet.js View on Github external
// number
          case 'e': // eslint-disable-line no-fallthrough
            // error
          default: // eslint-disable-line no-fallthrough
            var formatId = this._getNumberFormatId(workingCell, workingVal)
            if (formatId !== null) {
              var format = this.workBook.formatCodes[formatId]
              if (typeof format === 'undefined') {
                try {
                  workingVal = ssf.format(Number(formatId), Number(workingVal))
                } catch (e) {
                  workingVal = ''
                }
              } else if (format !== 'General') {
                try {
                  workingVal = ssf.format(format, Number(workingVal))
                } catch (e) {
                  workingVal = ''
                }
              }
            } else if (!isNaN(parseFloat(workingVal))) { // this is number
              workingVal = parseFloat(parseFloat(workingVal)) // parse to float or int
            }
            this.workingRow.values[cellNum] = workingVal || ''
            if (this.workBook.options.returnFormats) {
              this.workingRow.formats[cellNum] = format || ssf.get_table()[formatId]
            }
            workingCell = {}
        }
      }
      if (workingCell.name === 'v') {
        var colNum = this.getColumnNumber(this.currentCell.attributes.r)
github DaSpawn / xlsx-stream-reader / lib / worksheet.js View on Github external
// error
        default: // eslint-disable-line no-fallthrough
          if (self.options.formatting && workingVal) {
            if (self.workBook.hasFormatCodes) {
              var formatId = workingCell.attributes.s ? self.workBook.xfs[workingCell.attributes.s].attributes.numFmtId : 0
              if (typeof formatId !== 'undefined') {
                var format = self.workBook.formatCodes[formatId]
                if (typeof format === 'undefined') {
                  try {
                    workingVal = ssf.format(Number(formatId), Number(workingVal))
                  } catch (e) {
                    workingVal = ''
                  }
                } else if (format !== 'General') {
                  try {
                    workingVal = ssf.format(format, Number(workingVal))
                  } catch (e) {
                    workingVal = ''
                  }
                }
              }
            } else if (!isNaN(parseFloat(workingVal))) { // this is number
              workingVal = parseFloat(parseFloat(workingVal)) // parse to float or int
            }
          }

          self.workingRow.values[cellNum] = workingVal || ''

          workingCell = {}
      }
    }
    if (workingCell.name === 'v') {
github lambrojos / supersalmon / lib / worksheet.js View on Github external
break
          case 'str':
            // string (formula)
          case 'b': // eslint-disable-line no-fallthrough
            // boolean
          case 'n': // eslint-disable-line no-fallthrough
            // number
          case 'e': // eslint-disable-line no-fallthrough
            // error
          default: // eslint-disable-line no-fallthrough
            var formatId = this._getNumberFormatId(workingCell, workingVal)
            if (formatId !== null) {
              var format = this.workBook.formatCodes[formatId]
              if (typeof format === 'undefined') {
                try {
                  workingVal = ssf.format(Number(formatId), Number(workingVal))
                } catch (e) {
                  workingVal = ''
                }
              } else if (format !== 'General') {
                try {
                  workingVal = ssf.format(format, Number(workingVal))
                } catch (e) {
                  workingVal = ''
                }
              }
            } else if (!isNaN(parseFloat(workingVal))) { // this is number
              workingVal = parseFloat(parseFloat(workingVal)) // parse to float or int
            }
            this.workingRow.values[cellNum] = workingVal || ''
            if (this.workBook.options.returnFormats) {
              this.workingRow.formats[cellNum] = format || ssf.get_table()[formatId]
github DaSpawn / xlsx-stream-reader / lib / worksheet.js View on Github external
// string (formula)
        case 'b': // eslint-disable-line no-fallthrough
          // boolean
        case 'n': // eslint-disable-line no-fallthrough
          // number
        case 'e': // eslint-disable-line no-fallthrough
          // error
        default: // eslint-disable-line no-fallthrough
          if (self.options.formatting && workingVal) {
            if (self.workBook.hasFormatCodes) {
              var formatId = workingCell.attributes.s ? self.workBook.xfs[workingCell.attributes.s].attributes.numFmtId : 0
              if (typeof formatId !== 'undefined') {
                var format = self.workBook.formatCodes[formatId]
                if (typeof format === 'undefined') {
                  try {
                    workingVal = ssf.format(Number(formatId), Number(workingVal))
                  } catch (e) {
                    workingVal = ''
                  }
                } else if (format !== 'General') {
                  try {
                    workingVal = ssf.format(format, Number(workingVal))
                  } catch (e) {
                    workingVal = ''
                  }
                }
              }
            } else if (!isNaN(parseFloat(workingVal))) { // this is number
              workingVal = parseFloat(parseFloat(workingVal)) // parse to float or int
            }
          }
github SheetJS / js-harb / harb.flow.js View on Github external
for(var R = 0; R != data.length; ++R) {
		for(var C = 0; C != data[R].length; ++C) {
			if(data[R][C] == null) continue;
			var cell/*:Cell*/ = ({v: data[R][C] }/*:any*/);
			if(range.s.r > R) range.s.r = R;
			if(range.s.c > C) range.s.c = C;
			if(range.e.r < R) range.e.r = R;
			if(range.e.c < C) range.e.c = C;
			var cell_ref = encode_cell(({c:C,r:R}/*:any*/));
			if(typeof cell.v === 'number') cell.t = 'n';
			else if(typeof cell.v === 'boolean') cell.t = 'b';
			else if(cell.v instanceof Date) {
				cell.t = 'n';
				cell.z = o.dateNF || SSF._table[14];
				cell.v = datenum(cell.v);
				cell.w = SSF.format(cell.z, cell.v);
			}
			else cell.t = 's';
			ws[cell_ref] = cell;
		}
	}
	if(range.s.c < 10000000) ws['!ref'] = encode_range(range);
	return ws;
}
github Claviz / xlstream / src / index.ts View on Github external
value = isNaN(value) ? value : Number(value);
                            let column = ch.attribs.r.replace(/[0-9]/g, '');
                            const index = lettersToNumber(column) - 1;
                            if (options.withHeader) {
                                if (!parsingHeader && header.length) {
                                    column = header[index];
                                } else {
                                    header[index] = value;
                                    parsingHeader = true;
                                }
                            }
                            arr[index] = value;
                            obj[column] = value;
                            const formatId = ch.attribs.s ? Number(ch.attribs.s) : 0;
                            if (formatId) {
                                value = ssf.format(formats[formatId], value);
                                value = isNaN(value) ? value : Number(value);
                            }
                            formattedArr[index] = value;
                            formattedObj[column] = value;
                        }
                    }
                    done(undefined, parsingHeader || (options.ignoreEmpty && !arr.length) ? null : {
                        raw: {
                            obj,
                            arr
                        },
                        formatted: {
                            obj: formattedObj,
                            arr: formattedArr,
                        },
                        header,

ssf

Format data using ECMA-376 spreadsheet Format Codes

Apache-2.0
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis