Zero-dependency spreadsheet engine. Read & write XLSX, CSV, ODS. Pure TypeScript, works everywhere.
翻译准备中
正在加载完整 README。
查看完整 README ↗[!NOTE] The only official sources for hucre are this repository (productdevbook/hucre) and the
hucrepackage on npm. The website hucre.dev is not affiliated with this project.
npm install hucre
import { readXlsx, writeXlsx } from "hucre"
// Read an XLSX file
const workbook = await readXlsx(buffer)
console.log(workbook.sheets[0].rows)
// Write an XLSX file
const xlsx = await writeXlsx({
sheets: [
{
name: "Products",
columns: [
{ header: "Name", key: "name", width: 25 },
{ header: "Price", key: "price", width: 12, numFmt: "$#,##0.00" },
{ header: "Stock", key: "stock", width: 10 },
],
data: [
{ name: "Widget", price: 9.99, stock: 142 },
{ name: "Gadget", price: 24.5, stock: 87 },
],
},
],
})
Import only what you need:
import { readXlsx, writeXlsx } from "hucre/xlsx" // XLSX only
import { parseCsv, writeCsv } from "hucre/csv" // CSV only (~2 KB gzipped)
import { readOds, writeOds } from "hucre/ods" // ODS only
import { parseJson, writeNdjson } from "hucre/json" // JSON / NDJSON
import { readXml, writeXml } from "hucre/xml" // Tabular XML
| hucre | SheetJS CE | ExcelJS | xlsx-js-style | |
|---|---|---|---|---|
| Dependencies | 0 | 0* | 9 | 0* |
| Bundle (gzip) | 4–129 KB† | ~300 KB | ~500 KB | ~300 KB |
| ESM native | Yes | Partial | No (CJS) | Partial |
| TypeScript | Native | Bolted-on | Bolted-on | Bolted-on |
| Edge runtime | Yes | No | No | No |
| CSP compliant | Yes | Yes | No (eval) | Yes |
| npm published | Yes | No (CDN only) | Stale | Yes |
| Read + Write | Yes | Yes (Pro $) | Yes | Yes |
| Styling | Yes | No (Pro $) | Yes | Yes |
| Cond. formatting | 13 types‡ | No (Pro $) | Yes | No |
| Stream read + write | Yes | CSV only | Yes | CSV only |
| ODS support | Yes§ | Yes | No | Yes |
| Round-trip | Yes | Partial | Partial | Partial |
| Sparklines | Yes | No | No | No |
| Tables | Yes | Yes | Yes | Yes |
| Images | Yes | No (Pro $) | Yes | No |
* SheetJS removed itself from npm; must install from CDN tarball.
† Depends on what you import — hucre is fully tree-shakeable, so there is no
single number. Minified + gzipped, bundled with rolldown against dist/:
{ parseCsv, writeCsv } from hucre/csv = 3.7 KB, { readXlsx } from
hucre/xlsx = 34 KB, { readXlsx, writeXlsx } = 68 KB, the entire
library (export * from "hucre") = 129 KB.
These four are measured by bun run size and pinned in
scripts/size-budget.json, so CI fails when one grows past its budget.
They are in the README because they had already drifted once — the
previous figures (2.3 / 32 / 64 / 114 KB) were true when written and were
enforced by nothing.
‡ cellIs, expression, colorScale, dataBar, iconSet, containsText,
notContainsText, beginsWith, endsWith, containsBlanks,
notContainsBlanks, duplicateValues, uniqueValues — read and written.
top10 and aboveAverage round-trip in their default form only (the writer
emits no rank / percent / bottom or aboveAverage / equalAverage /
stdDev attributes), and timePeriod rules are dropped on read.
§ Values, formulas and merges round-trip in full; cell styling covers six facets (bold, italic, size, font colour, background colour, number format). Borders, alignment, column widths, freeze panes, validation, named ranges, images and page setup are not modelled in either direction, so ODS → ODS is lossless while XLSX → ODS drops them. See What ODS carries.
以上为 README 的开头部分。其余内容请阅读原文。 查看完整 README ↗