Cell Value Types and Number Formats — Strings, Numbers, Dates, Times, Booleans

level: basic / verified: 2026-10-01 / tabs: Node.js・Python・Java・WebAssembly / 日本語

What you want to do

Use the correct setter for each type of value you put into a cell (string / number / date / time / boolean), specify number formats, and understand the difference between getValue() and getValue(true).

Type quick reference

Value to storeMethodExample
StringsetValue(str)setValue("Apple")
NumbersetNumberValue(num)setNumberValue(1234.5)
Date / timesetDateValue(dateTimeObject)setDateValue(d)
Date / time (from a string)setDateStringValue(str)setDateStringValue("2024-01-15")
BooleansetBooleanValue(bool)setBooleanValue(true)
Let the type be detected automaticallysetValue(str)setValue("2024/1/15") → becomes a date
FormulasetFormula(str)setFormula("SUM(A1:A3)")

All setters share the same second and third arguments (forceString?, numberFormat?) (setDateStringValue / setValue included).

Code

Output:

// value-types.js — per-type setters and number formats, raw vs. display values
const { nodeosbxl, dto } = require("nodeosbxl");

const app = new nodeosbxl.App();
const wb = app.createWorkBook("value-types.xlsx");
const ws = wb.openWorkSheet("Sheet1");

const show = (a1) => {
    const r = ws.getRange(`${a1}:${a1}`);
    console.log(`  ${a1}: disp=${JSON.stringify(r.getValue()[a1])}` +
                ` raw=${JSON.stringify(r.getValue(true)[a1])}` +
                ` fmt=${JSON.stringify(r.getNumberFormat()[a1])}`);
};

// --- dates & times ---
// Create a DateTimeObject with no arguments, then set its contents with setYMD() / setHMS()
const date = new dto.DateTimeObject();
date.setYMD(2024, 1, 15);

const datetime = new dto.DateTimeObject();
datetime.setYMD(2024, 1, 15);
datetime.setHMS(13, 45, 30);

const time = new dto.DateTimeObject();
time.setHMS(9, 5, 0);

console.log("[Dates & times]");
ws.getRange("A1:A1").setDateValue(date);                      // date only
ws.getRange("A2:A2").setDateValue(datetime);                  // date + time
ws.getRange("A3:A3").setDateValue(time);                      // time only
ws.getRange("A4:A4").setDateStringValue("2024-01-15");        // from a string
ws.getRange("A5:A5").setDateStringValue("令和6年1月15日");      // Japanese era (wareki) dates are recognized too
ws.getRange("A6:A6").setDateValue(date, false, "yyyy-mm-dd");  // number format can be given at the same time
ws.getRange("A7:A7").setDateValue(date, false, "ggge年m月d日"); // wareki + unquoted Japanese literals also work
["A1", "A2", "A3", "A4", "A5", "A6", "A7"].forEach(show);

// --- numbers & strings ---
console.log("[Numbers & strings]");
ws.getRange("B1:B1").setNumberValue(1234567.891);
ws.getRange("B2:B2").setNumberValue(1234567.891, false, "#,##0.00");
ws.getRange("B3:B3").setNumberValue(0.25, false, "0.0%");
ws.getRange("B4:B4").setValue("00123");      // leading zeros are kept as a string
ws.getRange("B5:B5").setValue("2024/1/15");  // the generic setter auto-detects dates
ws.getRange("B6:B6").setValue("12345", true); // forceString=true forces string handling
ws.getRange("B7:B7").setNumberValue(1234.5, false, '"円"#,##0');   // quoted literal ("yen")
ws.getRange("B8:B8").setNumberValue(-1234.5, false, "#,##0;赤-#,##0"); // bare color token (red) → [Red]
["B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8"].forEach(show);

// --- booleans ---
console.log("[Booleans]");
ws.getRange("C1:C1").setBooleanValue(true);
ws.getRange("C2:C2").setBooleanValue(false);
ws.getRange("C3:C3").setFormula("TRUE");     // a formula can produce a boolean too
["C1", "C2", "C3"].forEach(show);

// --- date serial values ---
console.log("[Serial values]");
console.log("  serial value of 2024/1/15 =", app.getNumericValue(date));
console.log("  with the 1904 date system =", app.getNumericValue(date, true));
console.log("  wb.isDate1904()           =", wb.isDate1904());

wb.save();
wb.close();
[Dates & times]
  A1: disp="2024/1/15" raw="45306" fmt="yyyy/m/d;@"
  A2: disp="2024/1/15 13:45:30" raw="45306.573263888888" fmt="yyyy/m/d h:mm:ss;@"
  A3: disp="9:05:00" raw="0.37847222222222221" fmt="h:mm:ss;@"
  A4: disp="2024/1/15" raw="45306" fmt="yyyy/m/d;@"
  A5: disp="2024/1/15" raw="45306" fmt="yyyy/m/d;@"
  A6: disp="2024-01-15" raw="45306" fmt="yyyy-mm-dd"
  A7: disp="令和6年1月15日" raw="45306" fmt="ggge年m月d日"
[Numbers & strings]
  B1: disp="1234567.891" raw="1234567.8910000001" fmt="General"
  B2: disp="1,234,567.89" raw="1234567.8910000001" fmt="#,##0.00"
  B3: disp="25.0%" raw="0.25" fmt="0.0%"
  B4: disp="00123" raw="00123" fmt="General"
  B5: disp="2024/01/15" raw="45306" fmt="yyyy/mm/dd"
  B6: disp="12345" raw="12345" fmt="General"
  B7: disp="円1,235" raw="1234.5" fmt="\"円\"#,##0"
  B8: disp="-1,235" raw="-1234.5" fmt="#,##0;赤-#,##0"
[Booleans]
  C1: disp="TRUE" raw="TRUE" fmt="General"
  C2: disp="FALSE" raw="FALSE" fmt="General"
  C3: disp="TRUE" raw="TRUE" fmt="General"
[Serial values]
  serial value of 2024/1/15 = 45306
  with the 1904 date system = 43844
  wb.isDate1904()           = false

Notes

getValue() vs. getValue(true)

CallReturnsUse it for
getValue()Display value (string after applying the number format)Report output, on-screen display, CSV export
getValue(true)Raw value (internally stored value; dates are serial values, formulas are results)Calculation, comparison, numeric processing

Both return a map like { "A1": "...", ... } and all values are strings. Convert with Number(...) when treating them as numbers.

const raw = Number(ws.getRange("A1:A1").getValue(true)["A1"]);   // 45306
const disp = ws.getRange("A1:A1").getValue()["A1"];              // "2024/1/15"

Dates

Numbers and strings

Caveats

See also