@origints/xlsx 0.1.0 → 0.1.1
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/README.md +184 -0
- package/package.json +11 -11
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# @origints/xlsx
|
|
2
|
+
|
|
3
|
+
> XLSX parsing for Origins with full traceability to sheets, ranges, and cells.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
Extracting data from Excel files often means losing track of where values came from. When a number is wrong, you can't easily trace it back to cell B47 on the "Q3 Sales" sheet.
|
|
10
|
+
|
|
11
|
+
This package provides rich navigation APIs for Excel workbooks while maintaining complete provenance. Every value knows its exact location: workbook, sheet, row, column, and cell address.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- Parse XLSX files from streams, buffers, or file paths
|
|
18
|
+
- Navigate workbooks, sheets, ranges, and cells
|
|
19
|
+
- Cursor-based iteration for sequential processing
|
|
20
|
+
- Cell predicates for conditional extraction
|
|
21
|
+
- Convert ranges to JSON, arrays, or objects
|
|
22
|
+
- Export to CSV format
|
|
23
|
+
- Full source location tracking for every cell
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @origints/xlsx @origints/core
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { parseXlsxFile } from "@origints/xlsx";
|
|
35
|
+
|
|
36
|
+
const result = await parseXlsxFile("data.xlsx");
|
|
37
|
+
|
|
38
|
+
if (result.ok) {
|
|
39
|
+
const workbook = result.value;
|
|
40
|
+
const sheet = workbook.getSheet("Sheet1");
|
|
41
|
+
const value = sheet.cell("A1").asString();
|
|
42
|
+
console.log(value);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Expected output:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
Hello
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
- Supported platforms:
|
|
57
|
+
- macOS / Linux / Windows
|
|
58
|
+
- Runtime requirements:
|
|
59
|
+
- Node.js >= 18
|
|
60
|
+
- Package managers:
|
|
61
|
+
- npm, pnpm, yarn
|
|
62
|
+
- Peer dependencies:
|
|
63
|
+
- @origints/core ^0.1.0
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install @origints/xlsx @origints/core
|
|
67
|
+
# or
|
|
68
|
+
pnpm add @origints/xlsx @origints/core
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
### Reading cells
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { parseXlsxFile } from "@origints/xlsx";
|
|
79
|
+
|
|
80
|
+
const result = await parseXlsxFile("report.xlsx");
|
|
81
|
+
|
|
82
|
+
if (result.ok) {
|
|
83
|
+
const sheet = result.value.getSheet("Data");
|
|
84
|
+
|
|
85
|
+
const name = sheet.cell("A1").asString();
|
|
86
|
+
const amount = sheet.cell("B1").asNumber();
|
|
87
|
+
const date = sheet.cell("C1").asDate();
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Working with ranges
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const sheet = workbook.getSheet("Sales");
|
|
95
|
+
|
|
96
|
+
// Get a range
|
|
97
|
+
const range = sheet.range("A1:D10");
|
|
98
|
+
|
|
99
|
+
// Convert to array of arrays
|
|
100
|
+
const rows = rangeToArray(range);
|
|
101
|
+
|
|
102
|
+
// Convert to objects using first row as headers
|
|
103
|
+
const records = rangeToObjects(range);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Cursor-based iteration
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { XlsxCursor } from "@origints/xlsx";
|
|
110
|
+
|
|
111
|
+
const cursor = new XlsxCursor(sheet, "A1");
|
|
112
|
+
|
|
113
|
+
// Move and grab values
|
|
114
|
+
cursor.move("right", 2);
|
|
115
|
+
const value = cursor.grab();
|
|
116
|
+
|
|
117
|
+
// Iterate rows
|
|
118
|
+
while (cursor.hasMore("down")) {
|
|
119
|
+
const row = cursor.grabRow(4);
|
|
120
|
+
cursor.move("down");
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Using with Origins plans
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { Planner, loadFile, globalRegistry } from "@origints/core";
|
|
128
|
+
import { parseXlsx, registerXlsxTransforms } from "@origints/xlsx";
|
|
129
|
+
|
|
130
|
+
registerXlsxTransforms(globalRegistry);
|
|
131
|
+
|
|
132
|
+
const plan = Planner.in(loadFile("data.xlsx"))
|
|
133
|
+
.mapIn(parseXlsx())
|
|
134
|
+
.emit((out, $) => {
|
|
135
|
+
const sheet = $.getSheet("Summary");
|
|
136
|
+
out.add("total", sheet.cell("B10").asNumber());
|
|
137
|
+
})
|
|
138
|
+
.compile();
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Export to CSV
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { sheetToCsv, rangeToCsv } from "@origints/xlsx";
|
|
145
|
+
|
|
146
|
+
const csv = sheetToCsv(sheet);
|
|
147
|
+
// or for a specific range
|
|
148
|
+
const rangeCsv = rangeToCsv(sheet.range("A1:C10"));
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Project Status
|
|
154
|
+
|
|
155
|
+
- **Experimental** - APIs may change
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Non-Goals
|
|
160
|
+
|
|
161
|
+
- Not an XLSX writer/generator
|
|
162
|
+
- Not a formula evaluator
|
|
163
|
+
- Not a chart/image extractor
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Documentation
|
|
168
|
+
|
|
169
|
+
- See `@origints/core` for Origins concepts
|
|
170
|
+
- See [exceljs](https://www.npmjs.com/package/exceljs) for underlying parser
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Contributing
|
|
175
|
+
|
|
176
|
+
- Open an issue before large changes
|
|
177
|
+
- Keep PRs focused
|
|
178
|
+
- Tests required for new features
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@origints/xlsx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "XLSX parsing for Origins with full traceability to sheets, ranges, and cells.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,13 @@
|
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vite build",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"lint": "eslint \"{src,tests}/**/*.{ts,tsx}\" --max-warnings 0",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
|
+
},
|
|
23
30
|
"dependencies": {
|
|
24
31
|
"exceljs": "^4.4.0"
|
|
25
32
|
},
|
|
@@ -27,20 +34,13 @@
|
|
|
27
34
|
"@origints/core": "^0.1.0"
|
|
28
35
|
},
|
|
29
36
|
"devDependencies": {
|
|
37
|
+
"@origints/core": "workspace:*",
|
|
30
38
|
"@types/node": "25.0.6",
|
|
31
39
|
"@vitest/coverage-v8": "^4.0.16",
|
|
32
40
|
"eslint": "9.39.2",
|
|
33
41
|
"typescript": "5.9.3",
|
|
34
42
|
"vite": "7.3.1",
|
|
35
43
|
"vite-plugin-dts": "4.5.4",
|
|
36
|
-
"vitest": "4.0.16"
|
|
37
|
-
"@origints/core": "0.1.0"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "vite build",
|
|
41
|
-
"test": "vitest run",
|
|
42
|
-
"test:coverage": "vitest run --coverage",
|
|
43
|
-
"lint": "eslint \"{src,tests}/**/*.{ts,tsx}\" --max-warnings 0",
|
|
44
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
44
|
+
"vitest": "4.0.16"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|