From acdc0d5ffff0f5b0a2f04bfe8e797842d87e1d14 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Fri, 3 Jan 2014 11:45:11 -0500 Subject: [PATCH] support for LO Calc's 'GENERAL' format --- ssf.js | 4 ++-- ssf.md | 11 ++++++++++- ssf_node.js | 3 +-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ssf.js b/ssf.js index 5c8d622..d01bd5f 100644 --- a/ssf.js +++ b/ssf.js @@ -350,12 +350,12 @@ function choose_fmt(fmt, v, o) { if(typeof v !== "number") return [fmt.length, fmt[3]]; return [l, v > 0 ? fmt[0] : v < 0 ? fmt[1] : fmt[2]]; } - var format = function format(fmt,v,o) { fixopts(o = (o||{})); - if(fmt === 0) return general_fmt(v, o); + if(fmt === 0 || (typeof fmt === "string" && fmt.toLowerCase() === "general")) return general_fmt(v, o); if(typeof fmt === 'number') fmt = table_fmt[fmt]; var f = choose_fmt(fmt, v, o); + if(f[1].toLowerCase() === "general") return general_fmt(v,o); return eval_fmt(f[1], v, o, f[0]); }; diff --git a/ssf.md b/ssf.md index 7d1b43e..54eb58b 100644 --- a/ssf.md +++ b/ssf.md @@ -699,10 +699,19 @@ function choose_fmt(fmt, v, o) { if(typeof v !== "number") return [fmt.length, fmt[3]]; return [l, v > 0 ? fmt[0] : v < 0 ? fmt[1] : fmt[2]]; } +``` +Finally, the format wrapper brings everything together: + +``` var format = function format(fmt,v,o) { fixopts(o = (o||{})); - if(fmt === 0) return general_fmt(v, o); +``` + +LibreOffice appears to emit the format "GENERAL" for general: + +``` + if(fmt === 0 || (typeof fmt === "string" && fmt.toLowerCase() === "general")) return general_fmt(v, o); if(typeof fmt === 'number') fmt = table_fmt[fmt]; var f = choose_fmt(fmt, v, o); return eval_fmt(f[1], v, o, f[0]); diff --git a/ssf_node.js b/ssf_node.js index 1d2b95a..7a95ef9 100644 --- a/ssf_node.js +++ b/ssf_node.js @@ -350,10 +350,9 @@ function choose_fmt(fmt, v, o) { if(typeof v !== "number") return [fmt.length, fmt[3]]; return [l, v > 0 ? fmt[0] : v < 0 ? fmt[1] : fmt[2]]; } - var format = function format(fmt,v,o) { fixopts(o = (o||{})); - if(fmt === 0) return general_fmt(v, o); + if(fmt === 0 || (typeof fmt === "string" && fmt.toLowerCase() === "general")) return general_fmt(v, o); if(typeof fmt === 'number') fmt = table_fmt[fmt]; var f = choose_fmt(fmt, v, o); return eval_fmt(f[1], v, o, f[0]);