Files and data

Treat CSV formula interpretation as a separate issue

CSV quoting does not stop spreadsheet applications from interpreting a cell as a formula. When exporting untrusted text for spreadsheets, choose a consumer-specific strategy and test it in that actual application.

Worked example

Node.js example · save as example.mjs and run node example.mjs

const values = ["ordinary", "=1+1", "+SUM(A1:A2)", "@example", "\t=2+2"];
const suspicious = value => /^[\s]*[=+@-]/.test(value);
console.log(values.map(value => [value, suspicious(value)]));

How it works

The example flags text for review rather than claiming to sanitize it. Leading characters and whitespace can influence interpretation, and some legitimate values such as negative numbers also match. A warning flag therefore requires a policy appropriate to the data and destination.

Limits and mistakes

Prefixing an apostrophe or quoting cells is not a universal guarantee across import and save workflows. Where possible, use a format that supports explicit text cell types. Keep the original data distinct from any spreadsheet-specific display transformation.

Check the result

Test formula-looking strings, negative numbers, whitespace prefixes, and exported files reopened by the intended spreadsheet program. Confirm both safe interpretation and preservation of legitimate text.

Sources

Reference documentation for the behavior used in this guide: