DIF to JSONDIF
Data Interchange Format.
A plain-text interchange format from the VisiCalc era, still offered as a save format by Excel and LibreOffice Calc and found in archived data. TabularJS reads the header, the optional label section and the data values.
A DIF file starts with a header (TABLE, VECTORS, TUPLES) followed by a DATA section in which every cell takes two lines: a type and value pair such as 0,709000 for a number, then a second line, which holds the text for a string cell. Each row starts with -1,0 and BOT, and the file ends with -1,0 and EOD.
TabularJS parses that layout and returns a single worksheet. DIF stores values only, so there are no formulas, styles or sheet names to extract.
Feature support
What TabularJS extracts from DIF files
- One worksheet. Numeric cells (type 0) become numbers, string cells (type 1) become strings, and short rows are padded with empty strings.
- Column titles from a
LABELsection when the file has one; otherwise A, B, C... - The title string of the
TABLEheader (Excel writes"EXCEL") inmeta.version, quotes included, and lines of aCOMMENTsection inmeta.comments. - The text encoding is detected by trying common codepages (cp850, cp437, Latin-1, UTF-8, UTF-16) unless you pass
encoding.
Convert DIF to JSON in Node.js
import tabularjs from 'tabularjs';
const result = await tabularjs('cities.dif');
const sheet = result.worksheets[0];
console.log(sheet.meta); // { version: '"EXCEL"' }
console.log(sheet.data[1]); // [ 'Oslo', 709000 ]
// Skip the detection when you know the encoding
const latin = await tabularjs('cities.dif', { encoding: 'latin1' });Read DIF files in the browser
import tabularjs from 'tabularjs';
const input = document.querySelector('input[type=file]');
input.addEventListener('change', async () => {
// In the browser, pass the encoding: detection works best in Node.js
const result = await tabularjs(input.files[0], { encoding: 'windows-1252' });
console.log(result.worksheets[0].data);
});JSON output
{
"worksheets": [
{
"data": [
["City", "Population"],
["Oslo", 709000],
["Bergen", 291000]
],
"columns": [{ "title": "A", "width": 100 }, { "title": "B", "width": 100 }],
"meta": { "version": "\"EXCEL\"" }
}
]
}Shape of the result for a small DIF file saved by Excel.
Options
| Option | Effect for DIF |
|---|---|
| encoding | Text encoding of the file. Default: detected. Any TextDecoder label, or a DOS codepage such as cp850 in Node.js. |
Limitations
- No formulas: DIF stores calculated values only.
- Encoding detection is a heuristic. It uses the optional chardet and iconv-lite packages, which are available in Node.js only; in the browser, pass
encodingwhen the file is not UTF-8 or Latin-1.
Frequently asked questions
What is a DIF file?
DIF (Data Interchange Format) is a text format created in 1980 for VisiCalc to move tables between programs. Excel and LibreOffice Calc can still save a sheet as .dif, and it shows up in old data archives.
Does a DIF file keep formulas or formatting?
No. DIF stores the values of one table, without formulas, styles or multiple sheets, so TabularJS returns a single worksheet of values.
Why do accented characters look wrong?
DIF files have no encoding marker, so the encoding is guessed. Pass it explicitly, for example { encoding: 'cp850' } for files written by DOS programs or { encoding: 'windows-1252' } for files from Excel on Windows.
Why TabularJS for DIF?
- No external spreadsheet parser dependencies: faster installs, smaller bundles.
- One API in Node.js and modern browsers.
- Output is shape-compatible withJspreadsheet: render parsed data in a live workbook with one call.