xls-reader 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +148 -5
- package/README.pt-BR.md +249 -0
- package/package.json +40 -19
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# xls-reader
|
|
2
|
+
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#22](https://github.com/zanlucathiago/xls-reader/pull/22) [`a00d7e1`](https://github.com/zanlucathiago/xls-reader/commit/a00d7e16c33ab57909046f571dd40e989d632fc1) Thanks [@zanlucathiago](https://github.com/zanlucathiago)! - Docs & discoverability: sharpen the npm description and keywords, and add an
|
|
8
|
+
"Convert an .xls to JSON" example plus an FAQ to the README (English and
|
|
9
|
+
pt-BR). No API changes.
|
|
10
|
+
|
|
11
|
+
## 0.1.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#1](https://github.com/zanlucathiago/xls-reader/pull/1) [`7cd6a31`](https://github.com/zanlucathiago/xls-reader/commit/7cd6a3127caa16fe2ecc3428b0b51cd51b5c4d45) Thanks [@zanlucathiago](https://github.com/zanlucathiago)! - Republish with npm provenance attestation and a rewritten README (badges,
|
|
16
|
+
comparison table vs SheetJS/ExcelJS, browser and error-handling examples). No
|
|
17
|
+
changes to the parser or public API.
|
|
18
|
+
|
|
19
|
+
## 0.1.0
|
|
20
|
+
|
|
21
|
+
Initial release. A zero-dependency reader for legacy `.xls` (BIFF8 / Excel
|
|
22
|
+
97–2003) files that returns each worksheet as a dense grid of typed cells
|
|
23
|
+
(strings, numbers, booleans, dates, and `null` for blank/error cells).
|
|
24
|
+
|
|
25
|
+
- OLE2 / Compound File container support, including mini streams.
|
|
26
|
+
- BIFF8 cell records: `LABELSST`, `LABEL`, `RSTRING`, `NUMBER`, `RK`, `MULRK`,
|
|
27
|
+
`BLANK`, `MULBLANK`, `BOOLERR`, and `FORMULA` (with its cached `STRING`
|
|
28
|
+
result).
|
|
29
|
+
- Shared-string table (`SST`) with `CONTINUE`-split strings.
|
|
30
|
+
- Date detection via `XF` + `FORMAT`, honoring the 1900 and 1904 date systems.
|
|
31
|
+
- Dual ESM/CJS output, full type declarations, and npm provenance.
|
package/README.md
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.npmjs.com/package/xls-reader">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/zanlucathiago/xls-reader/main/assets/banner.png" alt="xls-reader — zero-dependency reader for legacy .xls (BIFF8 / Excel 97–2003)" width="820" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/xls-reader"><img src="https://img.shields.io/npm/v/xls-reader.svg?color=cb3837&logo=npm" alt="npm version" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/xls-reader"><img src="https://img.shields.io/npm/dm/xls-reader.svg?color=cb3837&logo=npm" alt="npm downloads" /></a>
|
|
10
|
+
<a href="https://github.com/zanlucathiago/xls-reader/actions/workflows/ci.yml"><img src="https://github.com/zanlucathiago/xls-reader/actions/workflows/ci.yml/badge.svg" alt="CI status" /></a>
|
|
11
|
+
<a href="https://codecov.io/gh/zanlucathiago/xls-reader"><img src="https://codecov.io/gh/zanlucathiago/xls-reader/branch/main/graph/badge.svg" alt="coverage" /></a>
|
|
12
|
+
<a href="https://bundlephobia.com/package/xls-reader"><img src="https://img.shields.io/bundlephobia/minzip/xls-reader.svg?label=min%2Bgzip" alt="bundle size" /></a>
|
|
13
|
+
<img src="https://img.shields.io/badge/dependencies-0-brightgreen.svg" alt="zero dependencies" />
|
|
14
|
+
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/xls-reader.svg?color=blue" alt="MIT license" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<strong>English</strong> · <a href="./README.pt-BR.md">Português (BR)</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
Runs in Node and the browser — it only needs `Uint8Array` / `DataView`. It ships
|
|
22
|
+
as **~3.8 KB min+gzip with zero runtime dependencies**, dual ESM/CJS, fully typed,
|
|
23
|
+
and published to npm with [provenance](https://docs.npmjs.com/generating-provenance-statements).
|
|
6
24
|
|
|
7
25
|
```bash
|
|
8
26
|
npm install xls-reader
|
|
27
|
+
# or: pnpm add xls-reader / yarn add xls-reader
|
|
9
28
|
```
|
|
10
29
|
|
|
30
|
+
## Contents
|
|
31
|
+
|
|
32
|
+
- [Why this exists](#why-this-exists)
|
|
33
|
+
- [Usage](#usage)
|
|
34
|
+
- [Convert an .xls to JSON](#convert-an-xls-to-json)
|
|
35
|
+
- [API](#api)
|
|
36
|
+
- [Comparison](#comparison)
|
|
37
|
+
- [Supported](#supported)
|
|
38
|
+
- [Limitations](#limitations)
|
|
39
|
+
- [FAQ](#faq)
|
|
40
|
+
- [Contributing](#contributing)
|
|
41
|
+
|
|
11
42
|
## Why this exists
|
|
12
43
|
|
|
13
44
|
Modern readers like [ExcelJS](https://github.com/exceljs/exceljs) only handle the
|
|
@@ -45,6 +76,52 @@ import { readFirstSheet } from "xls-reader";
|
|
|
45
76
|
const sheet = readFirstSheet(bytes);
|
|
46
77
|
```
|
|
47
78
|
|
|
79
|
+
In the browser (e.g. from a file `<input>`):
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { readXls } from "xls-reader";
|
|
83
|
+
|
|
84
|
+
input.addEventListener("change", async () => {
|
|
85
|
+
const file = input.files?.[0];
|
|
86
|
+
if (!file) return;
|
|
87
|
+
const workbook = readXls(await file.arrayBuffer());
|
|
88
|
+
console.table(workbook.sheets[0]?.rows);
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Convert an .xls to JSON
|
|
93
|
+
|
|
94
|
+
Use the first row as the keys to turn a sheet into an array of JSON objects:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { readFirstSheet } from "xls-reader";
|
|
98
|
+
|
|
99
|
+
const sheet = readFirstSheet(bytes);
|
|
100
|
+
const [header = [], ...body] = sheet?.rows ?? [];
|
|
101
|
+
|
|
102
|
+
const json = body.map((row) =>
|
|
103
|
+
Object.fromEntries(header.map((key, i) => [String(key), row[i] ?? null])),
|
|
104
|
+
);
|
|
105
|
+
// [{ Emitente: "BANCO X S/A", Taxa: 1.1, Data: 2024-04-02T00:00:00.000Z }, ...]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Handling non-`.xls` input:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { readXls, XlsError } from "xls-reader";
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const workbook = readXls(bytes);
|
|
115
|
+
} catch (err) {
|
|
116
|
+
if (err instanceof XlsError) {
|
|
117
|
+
// Not a BIFF .xls — e.g. it's really an .xlsx, CSV, or HTML mislabeled as .xls
|
|
118
|
+
console.error(err.message);
|
|
119
|
+
} else {
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
48
125
|
## API
|
|
49
126
|
|
|
50
127
|
### `readXls(data: ArrayBuffer | Uint8Array): Workbook`
|
|
@@ -55,14 +132,20 @@ Parses a whole workbook. Throws `XlsError` if the bytes aren't a BIFF `.xls`.
|
|
|
55
132
|
|
|
56
133
|
The first worksheet, for the single-sheet case.
|
|
57
134
|
|
|
135
|
+
### `excelSerialToDate(serial: number, date1904: boolean): Date`
|
|
136
|
+
|
|
137
|
+
The raw serial-number → `Date` (UTC) conversion, if you need it directly.
|
|
138
|
+
|
|
58
139
|
### Types
|
|
59
140
|
|
|
60
141
|
```ts
|
|
61
142
|
type Cell = string | number | boolean | Date | null;
|
|
143
|
+
|
|
62
144
|
interface Sheet {
|
|
63
145
|
name: string;
|
|
64
146
|
rows: Cell[][]; // dense, null-padded to the last used column
|
|
65
147
|
}
|
|
148
|
+
|
|
66
149
|
interface Workbook {
|
|
67
150
|
sheets: Sheet[];
|
|
68
151
|
}
|
|
@@ -74,6 +157,22 @@ interface Workbook {
|
|
|
74
157
|
conversion.
|
|
75
158
|
- **Blank / error** cells are `null`.
|
|
76
159
|
|
|
160
|
+
## Comparison
|
|
161
|
+
|
|
162
|
+
| | **xls-reader** | SheetJS (`xlsx`) | ExcelJS |
|
|
163
|
+
| -------------------------------- | -------------- | --------------------- | ------- |
|
|
164
|
+
| Reads legacy `.xls` (BIFF8) | ✅ | ✅ | ❌ |
|
|
165
|
+
| Reads `.xlsx` (OOXML) | ❌ | ✅ | ✅ |
|
|
166
|
+
| Latest fixes on the npm registry | ✅ | ⚠️ frozen at `0.18.5` | ✅ |
|
|
167
|
+
| Runtime dependencies | **0** | several | several |
|
|
168
|
+
| Install size | ~4 KB min+gzip | large | large |
|
|
169
|
+
| npm provenance attestation | ✅ | ❌ | ❌ |
|
|
170
|
+
| Writes files / styling / charts | ❌ | ✅ | ✅ |
|
|
171
|
+
|
|
172
|
+
If you need to **write** spreadsheets, style cells, or read `.xlsx`, reach for
|
|
173
|
+
ExcelJS or SheetJS. `xls-reader` deliberately does one thing: get the values out
|
|
174
|
+
of a legacy `.xls`.
|
|
175
|
+
|
|
77
176
|
## Supported
|
|
78
177
|
|
|
79
178
|
- OLE2 / Compound File container (regular **and** mini streams).
|
|
@@ -91,6 +190,50 @@ interface Workbook {
|
|
|
91
190
|
- Dates before 1900-03-01 in the 1900 system are off by one day (Excel's
|
|
92
191
|
historical leap-year bug); real-world data is unaffected.
|
|
93
192
|
|
|
193
|
+
## FAQ
|
|
194
|
+
|
|
195
|
+
### How do I read an `.xls` file in Node.js?
|
|
196
|
+
|
|
197
|
+
Install `xls-reader`, read the file into bytes, and call `readXls` — no other
|
|
198
|
+
setup, no native modules:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
import { readFile } from "node:fs/promises";
|
|
202
|
+
import { readXls } from "xls-reader";
|
|
203
|
+
|
|
204
|
+
const workbook = readXls(await readFile("report.xls"));
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Is this a SheetJS (`xlsx`) alternative?
|
|
208
|
+
|
|
209
|
+
For **reading legacy `.xls`**, yes. SheetJS no longer publishes to npm, so
|
|
210
|
+
`xls-reader` is a small, npm-published, zero-dependency option when all you need
|
|
211
|
+
is the cell values. It does not write files or read `.xlsx` — for that, use
|
|
212
|
+
SheetJS or ExcelJS.
|
|
213
|
+
|
|
214
|
+
### Can it read `.xlsx` files?
|
|
215
|
+
|
|
216
|
+
No. `.xlsx` is the newer OOXML (zipped XML) format — a completely different
|
|
217
|
+
container. `xls-reader` handles the older binary BIFF8 `.xls` only. Use
|
|
218
|
+
[ExcelJS](https://github.com/exceljs/exceljs) for `.xlsx`.
|
|
219
|
+
|
|
220
|
+
### How do I convert an `.xls` to JSON?
|
|
221
|
+
|
|
222
|
+
See [Convert an .xls to JSON](#convert-an-xls-to-json) above — map each data row
|
|
223
|
+
onto the header row with `Object.fromEntries`.
|
|
224
|
+
|
|
225
|
+
### Does it work in the browser?
|
|
226
|
+
|
|
227
|
+
Yes. It only uses `Uint8Array` / `DataView`, so pass an `ArrayBuffer` (e.g. from
|
|
228
|
+
a file `<input>` or `fetch`) straight to `readXls`.
|
|
229
|
+
|
|
230
|
+
## Contributing
|
|
231
|
+
|
|
232
|
+
Bug reports, sample files, and PRs are very welcome — see
|
|
233
|
+
[CONTRIBUTING.md](./CONTRIBUTING.md). Please also read the
|
|
234
|
+
[Code of Conduct](./CODE_OF_CONDUCT.md). To report a security issue, see the
|
|
235
|
+
[Security Policy](./SECURITY.md).
|
|
236
|
+
|
|
94
237
|
## License
|
|
95
238
|
|
|
96
239
|
[MIT](./LICENSE) © Thiago Zanluca
|
package/README.pt-BR.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.npmjs.com/package/xls-reader">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/zanlucathiago/xls-reader/main/assets/banner.png" alt="xls-reader — leitor sem dependências para .xls legado (BIFF8 / Excel 97–2003)" width="820" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/xls-reader"><img src="https://img.shields.io/npm/v/xls-reader.svg?color=cb3837&logo=npm" alt="versão no npm" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/xls-reader"><img src="https://img.shields.io/npm/dm/xls-reader.svg?color=cb3837&logo=npm" alt="downloads no npm" /></a>
|
|
10
|
+
<a href="https://github.com/zanlucathiago/xls-reader/actions/workflows/ci.yml"><img src="https://github.com/zanlucathiago/xls-reader/actions/workflows/ci.yml/badge.svg" alt="status do CI" /></a>
|
|
11
|
+
<a href="https://codecov.io/gh/zanlucathiago/xls-reader"><img src="https://codecov.io/gh/zanlucathiago/xls-reader/branch/main/graph/badge.svg" alt="cobertura" /></a>
|
|
12
|
+
<a href="https://bundlephobia.com/package/xls-reader"><img src="https://img.shields.io/bundlephobia/minzip/xls-reader.svg?label=min%2Bgzip" alt="tamanho do bundle" /></a>
|
|
13
|
+
<img src="https://img.shields.io/badge/dependencies-0-brightgreen.svg" alt="zero dependências" />
|
|
14
|
+
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/xls-reader.svg?color=blue" alt="licença MIT" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="./README.md">English</a> · <strong>Português (BR)</strong>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
Roda no Node e no navegador — só precisa de `Uint8Array` / `DataView`. São
|
|
22
|
+
**~3,8 KB min+gzip com zero dependências de runtime**, saída dupla ESM/CJS,
|
|
23
|
+
totalmente tipado, e publicado no npm com
|
|
24
|
+
[provenance](https://docs.npmjs.com/generating-provenance-statements).
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install xls-reader
|
|
28
|
+
# ou: pnpm add xls-reader / yarn add xls-reader
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Conteúdo
|
|
32
|
+
|
|
33
|
+
- [Por que isso existe](#por-que-isso-existe)
|
|
34
|
+
- [Uso](#uso)
|
|
35
|
+
- [Converter um .xls para JSON](#converter-um-xls-para-json)
|
|
36
|
+
- [API](#api)
|
|
37
|
+
- [Comparação](#comparação)
|
|
38
|
+
- [Suportado](#suportado)
|
|
39
|
+
- [Limitações](#limitações)
|
|
40
|
+
- [FAQ](#faq)
|
|
41
|
+
- [Contribuindo](#contribuindo)
|
|
42
|
+
|
|
43
|
+
## Por que isso existe
|
|
44
|
+
|
|
45
|
+
Leitores modernos como o [ExcelJS](https://github.com/exceljs/exceljs) só lidam
|
|
46
|
+
com o formato mais novo `.xlsx` (OOXML). O leitor de `.xls` de facto,
|
|
47
|
+
[SheetJS](https://sheetjs.com), **não publica mais no registro do npm** — sua
|
|
48
|
+
última versão no npm (`0.18.5`) está congelada com vulnerabilidades conhecidas, e
|
|
49
|
+
as correções saem apenas do CDN próprio dele. Instalar de um CDN significa que o
|
|
50
|
+
`npm audit` e o Dependabot não enxergam o pacote, então você perde os alertas
|
|
51
|
+
automáticos de vulnerabilidade.
|
|
52
|
+
|
|
53
|
+
O `xls-reader` é uma alternativa pequena, focada e **publicada no npm** para o
|
|
54
|
+
caso comum: _ler as células de um `.xls` legado_. Sem dependências, licença MIT,
|
|
55
|
+
coberto pelas mesmas ferramentas de supply-chain do resto da sua árvore.
|
|
56
|
+
|
|
57
|
+
## Uso
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { readFile } from "node:fs/promises";
|
|
61
|
+
import { readXls } from "xls-reader";
|
|
62
|
+
|
|
63
|
+
const workbook = readXls(await readFile("posicao.xls"));
|
|
64
|
+
|
|
65
|
+
for (const sheet of workbook.sheets) {
|
|
66
|
+
console.log(sheet.name);
|
|
67
|
+
for (const row of sheet.rows) {
|
|
68
|
+
console.log(row); // ex.: ["BANCO DAYCOVAL S/A", "CDB", "CDI", 1.1, Date(2024-04-02), 1000, ...]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Atalho para uma única planilha:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { readFirstSheet } from "xls-reader";
|
|
77
|
+
|
|
78
|
+
const sheet = readFirstSheet(bytes);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
No navegador (ex.: a partir de um `<input>` de arquivo):
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { readXls } from "xls-reader";
|
|
85
|
+
|
|
86
|
+
input.addEventListener("change", async () => {
|
|
87
|
+
const file = input.files?.[0];
|
|
88
|
+
if (!file) return;
|
|
89
|
+
const workbook = readXls(await file.arrayBuffer());
|
|
90
|
+
console.table(workbook.sheets[0]?.rows);
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Converter um .xls para JSON
|
|
95
|
+
|
|
96
|
+
Use a primeira linha como chaves para transformar uma planilha em um array de
|
|
97
|
+
objetos JSON:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { readFirstSheet } from "xls-reader";
|
|
101
|
+
|
|
102
|
+
const sheet = readFirstSheet(bytes);
|
|
103
|
+
const [header = [], ...body] = sheet?.rows ?? [];
|
|
104
|
+
|
|
105
|
+
const json = body.map((row) =>
|
|
106
|
+
Object.fromEntries(header.map((key, i) => [String(key), row[i] ?? null])),
|
|
107
|
+
);
|
|
108
|
+
// [{ Emitente: "BANCO X S/A", Taxa: 1.1, Data: 2024-04-02T00:00:00.000Z }, ...]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Tratando uma entrada que não é `.xls`:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { readXls, XlsError } from "xls-reader";
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const workbook = readXls(bytes);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (err instanceof XlsError) {
|
|
120
|
+
// Não é um .xls BIFF — ex.: é na verdade um .xlsx, CSV ou HTML rotulado como .xls
|
|
121
|
+
console.error(err.message);
|
|
122
|
+
} else {
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API
|
|
129
|
+
|
|
130
|
+
### `readXls(data: ArrayBuffer | Uint8Array): Workbook`
|
|
131
|
+
|
|
132
|
+
Faz o parsing do workbook inteiro. Lança `XlsError` se os bytes não forem um
|
|
133
|
+
`.xls` BIFF.
|
|
134
|
+
|
|
135
|
+
### `readFirstSheet(data): Sheet | undefined`
|
|
136
|
+
|
|
137
|
+
A primeira planilha, para o caso de uma única aba.
|
|
138
|
+
|
|
139
|
+
### `excelSerialToDate(serial: number, date1904: boolean): Date`
|
|
140
|
+
|
|
141
|
+
A conversão bruta de número serial → `Date` (UTC), caso você precise dela
|
|
142
|
+
diretamente.
|
|
143
|
+
|
|
144
|
+
### Tipos
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
type Cell = string | number | boolean | Date | null;
|
|
148
|
+
|
|
149
|
+
interface Sheet {
|
|
150
|
+
name: string;
|
|
151
|
+
rows: Cell[][]; // densa, preenchida com null até a última coluna usada
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface Workbook {
|
|
155
|
+
sheets: Sheet[];
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
- **Números** voltam como `number` (tanto na codificação `NUMBER` quanto na
|
|
160
|
+
compacta `RK`).
|
|
161
|
+
- **Datas** — um número cujo formato de célula é de data/hora (embutido ou
|
|
162
|
+
customizado) volta como `Date` (UTC). Use `excelSerialToDate` se precisar da
|
|
163
|
+
conversão bruta.
|
|
164
|
+
- Células **em branco / de erro** viram `null`.
|
|
165
|
+
|
|
166
|
+
## Comparação
|
|
167
|
+
|
|
168
|
+
| | **xls-reader** | SheetJS (`xlsx`) | ExcelJS |
|
|
169
|
+
| ------------------------------------- | -------------- | ------------------------ | ------- |
|
|
170
|
+
| Lê `.xls` legado (BIFF8) | ✅ | ✅ | ❌ |
|
|
171
|
+
| Lê `.xlsx` (OOXML) | ❌ | ✅ | ✅ |
|
|
172
|
+
| Correções recentes no registro do npm | ✅ | ⚠️ congelado em `0.18.5` | ✅ |
|
|
173
|
+
| Dependências de runtime | **0** | várias | várias |
|
|
174
|
+
| Tamanho de instalação | ~4 KB min+gzip | grande | grande |
|
|
175
|
+
| Atestado de provenance no npm | ✅ | ❌ | ❌ |
|
|
176
|
+
| Escreve arquivos / estilos / gráficos | ❌ | ✅ | ✅ |
|
|
177
|
+
|
|
178
|
+
Se você precisa **escrever** planilhas, estilizar células ou ler `.xlsx`, use o
|
|
179
|
+
ExcelJS ou o SheetJS. O `xls-reader` faz uma coisa de propósito: extrair os
|
|
180
|
+
valores de um `.xls` legado.
|
|
181
|
+
|
|
182
|
+
## Suportado
|
|
183
|
+
|
|
184
|
+
- Container OLE2 / Compound File (streams normais **e** mini streams).
|
|
185
|
+
- Registros BIFF8: `LABELSST`, `LABEL`, `RSTRING`, `NUMBER`, `RK`, `MULRK`,
|
|
186
|
+
`BLANK`, `MULBLANK`, `BOOLERR`, `FORMULA` (+ seu resultado `STRING`).
|
|
187
|
+
- Tabela de strings compartilhadas (`SST`), incluindo strings divididas entre
|
|
188
|
+
registros `CONTINUE`.
|
|
189
|
+
- Detecção de datas via `XF` + `FORMAT`, e os sistemas de data 1900 / 1904.
|
|
190
|
+
|
|
191
|
+
## Limitações
|
|
192
|
+
|
|
193
|
+
- Somente leitura, e lê **valores** — não estilos, geometria de células
|
|
194
|
+
mescladas ou gráficos.
|
|
195
|
+
- Apenas BIFF8 (Excel 97+). Não lê os bem mais antigos BIFF5/BIFF2, nem os
|
|
196
|
+
arquivos HTML/XML que algumas ferramentas rotulam erradamente como `.xls`
|
|
197
|
+
(confira os magic bytes).
|
|
198
|
+
- Workbooks criptografados não são suportados.
|
|
199
|
+
- Datas anteriores a 1900-03-01 no sistema 1900 ficam com um dia de diferença
|
|
200
|
+
(o bug histórico de ano bissexto do Excel); dados do mundo real não são
|
|
201
|
+
afetados.
|
|
202
|
+
|
|
203
|
+
## FAQ
|
|
204
|
+
|
|
205
|
+
### Como leio um arquivo `.xls` no Node.js?
|
|
206
|
+
|
|
207
|
+
Instale o `xls-reader`, leia o arquivo em bytes e chame `readXls` — sem outra
|
|
208
|
+
configuração, sem módulos nativos:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { readFile } from "node:fs/promises";
|
|
212
|
+
import { readXls } from "xls-reader";
|
|
213
|
+
|
|
214
|
+
const workbook = readXls(await readFile("relatorio.xls"));
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### É uma alternativa ao SheetJS (`xlsx`)?
|
|
218
|
+
|
|
219
|
+
Para **ler `.xls` legado**, sim. O SheetJS não publica mais no npm, então o
|
|
220
|
+
`xls-reader` é uma opção pequena, publicada no npm e sem dependências quando você
|
|
221
|
+
só precisa dos valores das células. Ele não escreve arquivos nem lê `.xlsx` —
|
|
222
|
+
para isso, use SheetJS ou ExcelJS.
|
|
223
|
+
|
|
224
|
+
### Consegue ler arquivos `.xlsx`?
|
|
225
|
+
|
|
226
|
+
Não. `.xlsx` é o formato mais novo OOXML (XML zipado) — um container totalmente
|
|
227
|
+
diferente. O `xls-reader` lida apenas com o `.xls` binário BIFF8, mais antigo.
|
|
228
|
+
Use o [ExcelJS](https://github.com/exceljs/exceljs) para `.xlsx`.
|
|
229
|
+
|
|
230
|
+
### Como converto um `.xls` para JSON?
|
|
231
|
+
|
|
232
|
+
Veja [Converter um .xls para JSON](#converter-um-xls-para-json) acima — mapeie
|
|
233
|
+
cada linha de dados na linha de cabeçalho com `Object.fromEntries`.
|
|
234
|
+
|
|
235
|
+
### Funciona no navegador?
|
|
236
|
+
|
|
237
|
+
Sim. Ele só usa `Uint8Array` / `DataView`, então passe um `ArrayBuffer` (ex.: de
|
|
238
|
+
um `<input>` de arquivo ou `fetch`) direto para o `readXls`.
|
|
239
|
+
|
|
240
|
+
## Contribuindo
|
|
241
|
+
|
|
242
|
+
Relatos de bug, arquivos de exemplo e PRs são muito bem-vindos — veja
|
|
243
|
+
[CONTRIBUTING.md](./CONTRIBUTING.md). Leia também o
|
|
244
|
+
[Código de Conduta](./CODE_OF_CONDUCT.md). Para reportar um problema de
|
|
245
|
+
segurança, veja a [Política de Segurança](./SECURITY.md).
|
|
246
|
+
|
|
247
|
+
## Licença
|
|
248
|
+
|
|
249
|
+
[MIT](./LICENSE) © Thiago Zanluca
|
package/package.json
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xls-reader",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Zero-dependency
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Zero-dependency .xls (BIFF8 / Excel 97-2003) reader for Node and the browser — a lightweight SheetJS alternative that returns each worksheet as typed cells.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xls",
|
|
7
|
-
"
|
|
7
|
+
"xls-reader",
|
|
8
|
+
"read-xls",
|
|
9
|
+
"xls-to-json",
|
|
10
|
+
"xls-parser",
|
|
8
11
|
"excel",
|
|
12
|
+
"excel-reader",
|
|
13
|
+
"read-excel",
|
|
14
|
+
"biff8",
|
|
15
|
+
"biff",
|
|
9
16
|
"spreadsheet",
|
|
17
|
+
"spreadsheet-parser",
|
|
18
|
+
"legacy-excel",
|
|
19
|
+
"sheetjs-alternative",
|
|
20
|
+
"xlrd",
|
|
10
21
|
"ole2",
|
|
11
22
|
"cfb",
|
|
12
|
-
"legacy-excel",
|
|
13
23
|
"parser",
|
|
14
|
-
"
|
|
24
|
+
"zero-dependency",
|
|
25
|
+
"typescript",
|
|
26
|
+
"browser",
|
|
27
|
+
"node"
|
|
15
28
|
],
|
|
16
29
|
"license": "MIT",
|
|
17
30
|
"author": "Thiago Zanluca",
|
|
@@ -37,30 +50,38 @@
|
|
|
37
50
|
"files": [
|
|
38
51
|
"dist",
|
|
39
52
|
"README.md",
|
|
53
|
+
"README.pt-BR.md",
|
|
54
|
+
"CHANGELOG.md",
|
|
40
55
|
"LICENSE"
|
|
41
56
|
],
|
|
42
57
|
"sideEffects": false,
|
|
43
58
|
"engines": {
|
|
44
59
|
"node": ">=18"
|
|
45
60
|
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@changesets/changelog-github": "^0.7.0",
|
|
63
|
+
"@changesets/cli": "^2.31.0",
|
|
64
|
+
"@eslint/js": "^10.0.1",
|
|
65
|
+
"@types/node": "^26.0.0",
|
|
66
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
67
|
+
"eslint": "^10.6.0",
|
|
68
|
+
"prettier": "^3.4.2",
|
|
69
|
+
"tsup": "^8.3.5",
|
|
70
|
+
"typescript": "^6.0.3",
|
|
71
|
+
"typescript-eslint": "^8.18.1",
|
|
72
|
+
"vite": "^8.0.16",
|
|
73
|
+
"vitest": "^4.1.9"
|
|
74
|
+
},
|
|
46
75
|
"scripts": {
|
|
47
76
|
"build": "tsup",
|
|
48
77
|
"test": "vitest run",
|
|
49
78
|
"test:watch": "vitest",
|
|
79
|
+
"coverage": "vitest run --coverage",
|
|
50
80
|
"typecheck": "tsc --noEmit",
|
|
51
81
|
"lint": "eslint .",
|
|
52
82
|
"format": "prettier --write .",
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"eslint": "^9.17.0",
|
|
59
|
-
"prettier": "^3.4.2",
|
|
60
|
-
"tsup": "^8.3.5",
|
|
61
|
-
"typescript": "^5.7.2",
|
|
62
|
-
"typescript-eslint": "^8.18.1",
|
|
63
|
-
"vitest": "^2.1.8"
|
|
64
|
-
},
|
|
65
|
-
"packageManager": "pnpm@11.9.0"
|
|
66
|
-
}
|
|
83
|
+
"changeset": "changeset",
|
|
84
|
+
"version-packages": "changeset version",
|
|
85
|
+
"release": "changeset publish"
|
|
86
|
+
}
|
|
87
|
+
}
|