gridcraft-preview

中文文档
0.1.0发布于 2026/11/04(MIT OR Apache-2.0)TypeScriptCommonJS零依赖

Read-only XLSX/XLS spreadsheet viewer for the web, powered by GridCraft

原始使用文档
文档目录15 节
  1. Features
  2. Installation
  3. Usage
  4. Basic Example
  5. Loading from a URL
  6. HTML Integration
  7. API Reference
  8. GridCraftPreview
  9. Supported Languages
  10. Supported File Formats
  11. Browser Compatibility
  12. Size
  13. License
  14. Credits
  15. Links

GridCraft Preview

Read-only XLSX/XLS spreadsheet viewer for the web, powered by GridCraft.

Features

  • ✅ Open XLSX/XLS files from File/Blob objects
  • ✅ Sheet navigation - Switch between worksheets
  • ✅ Zoom controls - Zoom in/out/fit to window
  • ✅ Cell selection - Select and view cell contents (read-only)
  • ✅ Search - Find text in the current sheet
  • ✅ Copy - Copy cell contents to clipboard
  • ✅ Multi-language - 19 languages including English and Chinese
  • ✅ Theme switching - Light, dark, or auto (follows system)
  • ❌ No editing - All editing features are disabled

Installation

npm install gridcraft-preview

Usage

Basic Example

import init, { GridCraftPreview } from 'gridcraft-preview';

// Initialize WASM module (must be called once before using the preview)
await init();

// Create preview instance
const preview = new GridCraftPreview();

// Load a file
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files[0];
  if (file) {
    await preview.loadFile(file);
  }
});

// Control the view
preview.zoomIn();
preview.zoomOut();
preview.zoomToFit();
preview.setZoom(125); // 125%

// Navigate sheets
const sheets = preview.getSheetNames();
console.log('Available sheets:', sheets);
preview.switchSheet('Sheet2');

// Search
const matchCount = preview.find('total', { matchCase: false });
console.log(`Found ${matchCount} matches`);
preview.findNext();

// Internationalization
preview.setLanguage('zh'); // Switch to Chinese
preview.setLanguage('en'); // Switch back to English

// Theme
preview.setTheme('dark');
preview.setTheme('auto'); // Follow system preference

Loading from a URL

import init, { GridCraftPreview } from 'gridcraft-preview';

await init();

const preview = new GridCraftPreview();

// Fetch and load a spreadsheet
const response = await fetch('/data/spreadsheet.xlsx');
const blob = await response.blob();
await preview.loadFile(blob, 'spreadsheet.xlsx');

HTML Integration

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>GridCraft Preview Example</title>
</head>
<body>
  <div>
    <input type="file" id="fileInput" accept=".xlsx,.xls" />
    <button onclick="preview.zoomIn()">Zoom In</button>
    <button onclick="preview.zoomOut()">Zoom Out</button>
    <button onclick="preview.zoomToFit()">Fit</button>
  </div>
  
  <canvas id="gridcraft_canvas" style="width: 100%; height: 600px;"></canvas>

  <script type="module">
    import init, { GridCraftPreview } from './node_modules/gridcraft-preview/dist/index.js';

    await init();
    window.preview = new GridCraftPreview();

    document.getElementById('fileInput').addEventListener('change', async (e) => {
      const file = e.target.files[0];
      if (file) {
        await window.preview.loadFile(file);
      }
    });
  </script>
</body>
</html>

API Reference

See index.d.ts for complete TypeScript definitions.

GridCraftPreview

Main class for controlling the preview.

Constructor

const preview = new GridCraftPreview();

Methods

File Operations
  • loadFile(file: File | Blob, filename?: string): Promise<void> - Load a spreadsheet file
View Controls
  • zoomIn(): void - Zoom in
  • zoomOut(): void - Zoom out
  • zoomToFit(): void - Zoom to fit window
  • setZoom(percentage: number): void - Set specific zoom level
Sheet Navigation
  • getSheetNames(): string[] - Get all sheet names
  • getCurrentSheet(): string - Get current sheet name
  • switchSheet(name: string): void - Switch to a sheet
Selection
  • getSelection(): string - Get current selection range
  • selectRange(range: string): void - Select a range
  • find(query: string, options?: FindOptions): number - Find text
  • findNext(): boolean - Find next occurrence
  • findPrevious(): boolean - Find previous occurrence
Localization
  • setLanguage(lang: Language): void - Set interface language
  • setTheme(theme: Theme): void - Set color theme

Supported Languages

English (en), 简体中文 (zh), Español (es), 日本語 (ja), 한국어 (ko), Русский (ru), Português (pt), Deutsch (de), Čeština (cs), Français (fr), Српски (sr), Türkçe (tr), Polski (pl), Italiano (it), Українська (uk), Tiếng Việt (vi), Nederlands (nl), Română (ro), Ελληνικά (el)

Supported File Formats

  • XLSX - Excel 2007+ workbooks (full support)
  • XLSM - Excel macro-enabled workbooks (viewing only, no macros)
  • XLS - Excel 97-2003 workbooks (values and formulas, limited formatting)

Browser Compatibility

Requires a modern browser with WebGPU or WebGL2 support:

  • Chrome/Edge 79+
  • Firefox 51+
  • Safari 15+
  • Opera 66+

Size

  • Uncompressed WASM: ~3 MB
  • Gzipped: ~1 MB

License

Dual-licensed under MIT or Apache-2.0, at your option.

Credits

Built with GridCraft - open-source spreadsheet software from the ArtCraft team.

版本与发布记录

gridcraft-preview 共发布 2 个版本,首次发布于 2026/11/04;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.0latest2026/11/04今天
0.0.0-stage2026/11/04今天

关于 gridcraft-preview 的常见问题

gridcraft-preview 是什么?

只读的XLSX/XLS电子表格浏览器的网络,由GridCraft提供支持

如何安装 gridcraft-preview?

在项目目录运行 npm install gridcraft-preview,或使用 pnpm add / yarn add / bun add。

gridcraft-preview 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

gridcraft-preview 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

gridcraft-preview 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

gridcraft-preview 可以商用吗?

gridcraft-preview 使用 (MIT OR Apache-2.0) 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

gridcraft-preview 还在维护吗?

最新版本 0.1.0 发布于 2026/11/04(今天);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/11/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。