xls-reader 0.3.0 → 0.5.0
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 +27 -0
- package/README.md +31 -2
- package/README.pt-BR.md +32 -2
- package/dist/cli.mjs +992 -0
- package/dist/index.cjs +30 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.mts +8 -2
- package/dist/index.mjs +30 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# xls-reader
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#42](https://github.com/zanlucathiago/xls-reader/pull/42) [`8249bd0`](https://github.com/zanlucathiago/xls-reader/commit/8249bd003bbc9cc767ede1e23a7dba4fae5408e9) Thanks [@zanlucathiago](https://github.com/zanlucathiago)! - Return Excel error cells as a typed `CellError` instead of collapsing them to
|
|
8
|
+
`null`. A cell holding `#DIV/0!`, `#N/A`, `#REF!`, `#VALUE!`, `#NAME?`, `#NUM!`,
|
|
9
|
+
or `#NULL!` (whether a literal error or a formula's cached error result) now comes
|
|
10
|
+
back as `new CellError(code)` — distinct from a blank cell (`null`) and from a
|
|
11
|
+
text cell that happens to contain that string. Check `cell instanceof CellError`
|
|
12
|
+
and read `cell.code`; in JSON it serializes to `{ "code": "#DIV/0!" }`. Exports
|
|
13
|
+
the new `CellError` class and `ExcelErrorCode` type.
|
|
14
|
+
|
|
15
|
+
Behavior change: error cells were previously `null`. If you relied on that, treat
|
|
16
|
+
a `CellError` as empty explicitly.
|
|
17
|
+
|
|
18
|
+
## 0.4.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- [#37](https://github.com/zanlucathiago/xls-reader/pull/37) [`67fb30c`](https://github.com/zanlucathiago/xls-reader/commit/67fb30cc06f2dba2ea59becbb7bfeca2fbb82654) Thanks [@zanlucathiago](https://github.com/zanlucathiago)! - Add a `xls-reader` command-line tool. Run `npx xls-reader report.xls` to print a
|
|
23
|
+
workbook's cells as JSON without writing any code — handy for a quick look or a
|
|
24
|
+
shell pipeline, and directly runnable by agents/tooling. Flags: `--objects` (rows
|
|
25
|
+
as header-keyed objects), `--sheet <name|index>`, `--visible-only`, `--compact`,
|
|
26
|
+
plus `--help` / `--version`. It reads from a file argument and writes JSON to
|
|
27
|
+
stdout; errors go to stderr with a non-zero exit code. The library API is
|
|
28
|
+
unchanged.
|
|
29
|
+
|
|
3
30
|
## 0.3.0
|
|
4
31
|
|
|
5
32
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ npm install xls-reader
|
|
|
32
32
|
- [Why this exists](#why-this-exists)
|
|
33
33
|
- [Usage](#usage)
|
|
34
34
|
- [Convert an .xls to JSON](#convert-an-xls-to-json)
|
|
35
|
+
- [Command line](#command-line)
|
|
35
36
|
- [API](#api)
|
|
36
37
|
- [Comparison](#comparison)
|
|
37
38
|
- [Supported](#supported)
|
|
@@ -122,6 +123,26 @@ try {
|
|
|
122
123
|
}
|
|
123
124
|
```
|
|
124
125
|
|
|
126
|
+
## Command line
|
|
127
|
+
|
|
128
|
+
No code needed for a quick look or a shell pipeline — the package ships an
|
|
129
|
+
`xls-reader` bin that prints a workbook's cells as JSON to stdout:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npx xls-reader report.xls # every sheet, pretty-printed
|
|
133
|
+
npx xls-reader report.xls --objects # rows keyed by the header row
|
|
134
|
+
npx xls-reader report.xls --sheet 0 --compact > sheet0.json
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
| Flag | Effect |
|
|
138
|
+
| ------------------- | ---------------------------------------------- |
|
|
139
|
+
| `--objects` | Each row as an object keyed by the header row |
|
|
140
|
+
| `--sheet <name\|n>` | Only the sheet with this name or 0-based index |
|
|
141
|
+
| `--visible-only` | Skip hidden and very-hidden sheets |
|
|
142
|
+
| `--compact` | Single-line JSON (default is pretty-printed) |
|
|
143
|
+
|
|
144
|
+
JSON goes to stdout; errors go to stderr with a non-zero exit code.
|
|
145
|
+
|
|
125
146
|
## API
|
|
126
147
|
|
|
127
148
|
### `readXls(data: ArrayBuffer | Uint8Array): Workbook`
|
|
@@ -144,7 +165,12 @@ The raw serial-number → `Date` (UTC) conversion, if you need it directly.
|
|
|
144
165
|
### Types
|
|
145
166
|
|
|
146
167
|
```ts
|
|
147
|
-
type Cell = string | number | boolean | Date | null;
|
|
168
|
+
type Cell = string | number | boolean | Date | CellError | null;
|
|
169
|
+
|
|
170
|
+
// An Excel error value, e.g. new CellError("#DIV/0!"). `.code` is the error text.
|
|
171
|
+
class CellError {
|
|
172
|
+
readonly code: "#NULL!" | "#DIV/0!" | "#VALUE!" | "#REF!" | "#NAME?" | "#NUM!" | "#N/A";
|
|
173
|
+
}
|
|
148
174
|
|
|
149
175
|
type SheetVisibility = "visible" | "hidden" | "very-hidden";
|
|
150
176
|
|
|
@@ -163,7 +189,10 @@ interface Workbook {
|
|
|
163
189
|
- **Dates** — a number whose cell format is a date/time (built-in or custom) is
|
|
164
190
|
returned as a `Date` (UTC). Use `excelSerialToDate` if you need the raw
|
|
165
191
|
conversion.
|
|
166
|
-
- **
|
|
192
|
+
- **Error** cells come back as a `CellError` (e.g. `#DIV/0!`, `#N/A`) — check
|
|
193
|
+
`cell instanceof CellError` and read `cell.code`. In JSON they serialize to
|
|
194
|
+
`{ "code": "#DIV/0!" }`.
|
|
195
|
+
- **Blank** cells are `null`.
|
|
167
196
|
- **Visibility** — each sheet reports whether it's `visible`, `hidden`, or
|
|
168
197
|
`very-hidden`, so you can skip the hidden lookup/config tabs. Chart, macro, and
|
|
169
198
|
VBA substreams aren't worksheets and are left out of `workbook.sheets`.
|
package/README.pt-BR.md
CHANGED
|
@@ -33,6 +33,7 @@ npm install xls-reader
|
|
|
33
33
|
- [Por que isso existe](#por-que-isso-existe)
|
|
34
34
|
- [Uso](#uso)
|
|
35
35
|
- [Converter um .xls para JSON](#converter-um-xls-para-json)
|
|
36
|
+
- [Linha de comando](#linha-de-comando)
|
|
36
37
|
- [API](#api)
|
|
37
38
|
- [Comparação](#comparação)
|
|
38
39
|
- [Suportado](#suportado)
|
|
@@ -125,6 +126,27 @@ try {
|
|
|
125
126
|
}
|
|
126
127
|
```
|
|
127
128
|
|
|
129
|
+
## Linha de comando
|
|
130
|
+
|
|
131
|
+
Sem escrever código, para uma olhada rápida ou um pipeline no shell — o pacote
|
|
132
|
+
inclui um bin `xls-reader` que imprime as células de um workbook como JSON no
|
|
133
|
+
stdout:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npx xls-reader relatorio.xls # todas as planilhas, formatado
|
|
137
|
+
npx xls-reader relatorio.xls --objects # linhas com chaves do cabeçalho
|
|
138
|
+
npx xls-reader relatorio.xls --sheet 0 --compact > planilha0.json
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
| Flag | Efeito |
|
|
142
|
+
| ------------------- | ------------------------------------------------------- |
|
|
143
|
+
| `--objects` | Cada linha como objeto com chaves da linha de cabeçalho |
|
|
144
|
+
| `--sheet <nome\|n>` | Só a planilha com este nome ou índice (base 0) |
|
|
145
|
+
| `--visible-only` | Ignora planilhas `hidden` e `very-hidden` |
|
|
146
|
+
| `--compact` | JSON em uma linha (o padrão é formatado) |
|
|
147
|
+
|
|
148
|
+
O JSON vai para o stdout; erros vão para o stderr com código de saída diferente de zero.
|
|
149
|
+
|
|
128
150
|
## API
|
|
129
151
|
|
|
130
152
|
### `readXls(data: ArrayBuffer | Uint8Array): Workbook`
|
|
@@ -150,7 +172,12 @@ diretamente.
|
|
|
150
172
|
### Tipos
|
|
151
173
|
|
|
152
174
|
```ts
|
|
153
|
-
type Cell = string | number | boolean | Date | null;
|
|
175
|
+
type Cell = string | number | boolean | Date | CellError | null;
|
|
176
|
+
|
|
177
|
+
// Um valor de erro do Excel, ex.: new CellError("#DIV/0!"). `.code` é o texto do erro.
|
|
178
|
+
class CellError {
|
|
179
|
+
readonly code: "#NULL!" | "#DIV/0!" | "#VALUE!" | "#REF!" | "#NAME?" | "#NUM!" | "#N/A";
|
|
180
|
+
}
|
|
154
181
|
|
|
155
182
|
type SheetVisibility = "visible" | "hidden" | "very-hidden";
|
|
156
183
|
|
|
@@ -170,7 +197,10 @@ interface Workbook {
|
|
|
170
197
|
- **Datas** — um número cujo formato de célula é de data/hora (embutido ou
|
|
171
198
|
customizado) volta como `Date` (UTC). Use `excelSerialToDate` se precisar da
|
|
172
199
|
conversão bruta.
|
|
173
|
-
- Células **
|
|
200
|
+
- Células **de erro** voltam como `CellError` (ex.: `#DIV/0!`, `#N/A`) — teste
|
|
201
|
+
`cell instanceof CellError` e leia `cell.code`. Em JSON viram
|
|
202
|
+
`{ "code": "#DIV/0!" }`.
|
|
203
|
+
- Células **em branco** viram `null`.
|
|
174
204
|
- **Visibilidade** — cada planilha informa se é `visible`, `hidden` ou
|
|
175
205
|
`very-hidden`, então dá para pular as abas ocultas de lookup/config. Substreams
|
|
176
206
|
de gráfico, macro e VBA não são planilhas e ficam de fora de `workbook.sheets`.
|