All formats

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

Data values
Formulas
Styles
Merged cells
Comments
Column metadata

What TabularJS extracts from DIF files

Convert DIF to JSON in Node.js

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

js
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

json
{
  "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

OptionEffect for DIF
encodingText encoding of the file. Default: detected. Any TextDecoder label, or a DOS codepage such as cp850 in Node.js.

Limitations

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?