sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

Loading of an xlsx file does not terminate

Open nerdlich-media opened this issue 4 years ago • 1 comments

Hi ,

I am trying to read the 'Arbeitsmarkt-kommunal_07131001_Adenau_Stadt.xlsx' file from the zip container provided by "Arbeitsagentur Deutschland with the following command.

const data = readFileSync('./data/Arbeitsmarkt-kommunal_07131001_Adenau_Stadt.xlsx', 'utf-8');
const options = { sheets: 'Daten', raw: this._raw, type: "string" };
this._workbook = read(data, options);

Unfortunately the read command does not return any data even after waiting for 10 minutes. What can I do ?

nerdlich-media avatar Apr 21 '22 09:04 nerdlich-media

XLSX is a ZIP-based format, and ZIP files can contain byte sequences that are not valid UTF-8 bytes, so string should be avoided.

The recommended approach in NodeJS is buffer:

const { readFileSync } = require("fs");
const { read } = require("xlsx");

const data = readFileSync('./data/Arbeitsmarkt-kommunal_07131001_Adenau_Stadt.xlsx');
const options = { sheets: 'Daten', raw: this._raw, type: "buffer" };
this._workbook = read(data, options);

binary type represents "binary strings" (where each character code is between 0 and 255) and can exactly represent the data. This is not recommended in NodeJS since Buffers are more efficient:

const { readFileSync } = require("fs");
const { read } = require("xlsx");

const data = readFileSync('./data/Arbeitsmarkt-kommunal_07131001_Adenau_Stadt.xlsx', "binary");
const options = { sheets: 'Daten', raw: this._raw, type: "binary" };
this._workbook = read(data, options);

FYI you can also test in NodeJS using xlsx-cli, the package that houses the CLI:

$ curl -kLO https://statistik.arbeitsagentur.de/Statistikdaten/Detail/202112/arbeitsmarkt-kommunal/amk/amk-07131-0-202112-zip.zip
$ unzip amk-07131-0-202112-zip.zip Arbeitsmarkt-kommunal_07131001_Adenau_Stadt.xlsx
$ npx xlsx-cli --list-sheets Arbeitsmarkt-kommunal_07131001_Adenau_Stadt.xlsx
Deckblatt
Impressum
Daten
Statistik-Infoseite
$ npx xlsx-cli Arbeitsmarkt-kommunal_07131001_Adenau_Stadt.xlsx Daten | head -n 1
Daten
,,,,,,Arbeitsmarkt kommunal,,,,

SheetJSDev avatar Apr 21 '22 09:04 SheetJSDev