Read the source and its declared rule
This original output exercise emits only an Open XML worksheet-cell fragment. Source kind text with value=1+1 must stay text; treating its equals sign as permission to emit an f formula changes meaning. Numeric source cells follow their separate numeric representation.
| Record | Input JSON |
|---|---|
| Base input | {"kind":"text","value":"=1+1"} |
Compare the actual paths
Correct output uses inlineStr and escaped text content. It is a fragment type demonstration, not an XLSX package or an executed spreadsheet; no universal CSV quoting convention is asserted.
| Path | Output JSON |
|---|---|
| Misleading path | {"fragment":"<c><f>1+1</f></c>"} |
| Corrected path | {"fragment":"<c t=\"inlineStr\"><is><t>=1+1</t></is></c>"} |
import {DatabaseSync} from 'node:sqlite';
import {TextDecoder} from 'node:util';
import {inflateSync} from 'node:zlib';
import {posix} from 'node:path';
import {createHash} from 'node:crypto';
const rows=(db,sql)=>db.prepare(sql).all().map(r=>({...r}));
const failed=(action)=>{try{action();return null;}catch(e){return {code:e.errcode??e.code??e.name};}};
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
const escape=s=>s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
if(i.kind==='number')return {fragment:'<c><v>'+i.value+'</v></c>'};
if(!corrected&&i.value.startsWith('='))return {fragment:'<c><f>'+escape(i.value.slice(1))+'</f></c>'};
return {fragment:'<c t="inlineStr"><is><t>'+escape(i.value)+'</t></is></c>'};
};
const cases=[{"label":"misleading base","input":{"kind":"text","value":"=1+1"},"expected":{"fragment":"<c><f>1+1</f></c>"},"corrected":false},{"label":"corrected base","input":{"kind":"text","value":"=1+1"},"expected":{"fragment":"<c t=\"inlineStr\"><is><t>=1+1</t></is></c>"},"corrected":true},{"label":"ordinary text retains declared type","input":{"kind":"text","value":"Ada"},"expected":{"fragment":"<c t=\"inlineStr\"><is><t>Ada</t></is></c>"},"corrected":true},{"label":"genuine negative numeric cell","input":{"kind":"number","value":-2},"expected":{"fragment":"<c><v>-2</v></c>"},"corrected":true},{"label":"literal XML text is escaped","input":{"kind":"text","value":"A<&>"},"expected":{"fragment":"<c t=\"inlineStr\"><is><t>A<&></t></is></c>"},"corrected":true}];
for(const test of cases){
const actual=run(test.input,test.corrected);
assert.deepEqual(actual,test.expected,test.label);
console.log(test.label,actual);
}
Check boundaries before the next load
Ordinary Ada remains text, genuine−2 remains numeric, and A<&> is emitted with literal XML text escaped.
| Case | Input JSON | Expected output JSON |
|---|---|---|
| Ordinary text cell | {"kind":"text","value":"Ada"} | {"fragment":"<c t=\"inlineStr\"><is><t>Ada</t></is></c>"} |
| Actual negative number | {"kind":"number","value":-2} | {"fragment":"<c><v>-2</v></c>"} |
| XML-special text | {"kind":"text","value":"A<&>"} | {"fragment":"<c t=\"inlineStr\"><is><t>A<&></t></is></c>"} |
Should the leading equals sign create a formula here?
Show the worked answer
No. Source kind is text. Preserve=1+1 inside an inline string cell rather than changing it to formula 1+1.