How to use ssf - 9 common examples

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 lambrojos / supersalmon / lib / worksheet.js View on Github external
} 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)

        this.currentCell = {}

        this.workingRow.values[colNum] = workingPart || ''
      }
    } else {
      if (this.sheetData[nodeData[0].name]) {
        if (!Array.isArray(this.sheetData[nodeData[0].name])) {
          this.sheetData[nodeData[0].name] = [this.sheetData[nodeData[0].name]]
        }
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,
github SheetJS / js-harb / harb.flow.js View on Github external
function numdate(v/*:number*/)/*:Date*/ {
	var date = SSF.parse_date_code(v);
	var val = new Date();
	if(date == null) throw new Error("Bad Date Code: " + v);
	val.setUTCDate(date.d);
	val.setUTCMonth(date.m-1);
	val.setUTCFullYear(date.y);
	val.setUTCHours(date.H);
	val.setUTCMinutes(date.M);
	val.setUTCSeconds(date.S);
	return val;
}
github SheetJS / js-harb / harb.flow.js View on Github external
var ws/*:Worksheet*/ = ({}/*:any*/);
	var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0 }}/*:any*/);
	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;
}

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