Skip to main content

使用 boxednode 在 Box 中创建工作表

boxednode[^1] 是一种用于生成嵌入脚本的命令行工具的工具。它自动化了从源代码构建 NodeJS 的过程。

¥boxednode[^1] is a tool for generating command-line tools that embed scripts. It automates the process of building NodeJS from source.

SheetJS 是一个用于从电子表格读取和写入数据的 JavaScript 库。

¥SheetJS is a JavaScript library for reading and writing data from spreadsheets.

此演示使用 boxednode 和 SheetJS 创建独立的 CLI 工具,用于解析电子表格并转换为其他格式。

¥This demo uses boxednode and SheetJS to create a standalone CLI tool for parsing spreadsheets and converting to other formats.

测试部署

该演示在以下部署中进行了测试:

¥This demo was tested in the following deployments:

架构版本NodeJS日期
darwin-x642.4.022.2.02024-05-28
darwin-arm2.4.322.2.02024-05-25
win10-x642.4.216.20.22024-04-18
linux-x642.4.021.7.12024-03-21
linux-arm2.4.320.13.12024-05-26

集成详情

¥Integration Details

SheetJS NodeJS 模块 可以从脚本中需要。boxednode 将自动处理打包。

¥The SheetJS NodeJS module can be required from scripts. boxednode will automatically handle packaging.

脚本要求

¥Script Requirements

专门使用 SheetJS 库和 NodeJS 内置模块的脚本可以使用 boxednode 进行打包

¥Scripts that exclusively use SheetJS libraries and NodeJS built-in modules can be bundled using boxednode

演示脚本 xlsx-cli.js 在 NodeJS 中运行。这是一个用于读写电子表格的简单命令行工具。

¥The demo script xlsx-cli.js runs in NodeJS. It is a simple command-line tool for reading and writing spreadsheets.

完整示例

¥Complete Example

  1. 下载测试文件 https://xlsx.nodejs.cn/pres.numbers

    ¥Download the test file https://xlsx.nodejs.cn/pres.numbers:

curl -o pres.numbers https://xlsx.nodejs.cn/pres.numbers
  1. 下载 xlsx-cli.js

    ¥Download xlsx-cli.js

curl -o xlsx-cli.js https://xlsx.nodejs.cn/cli/xlsx-cli.js
  1. 安装依赖:

    ¥Install the dependencies:

yarn add https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz exit-on-epipe commander@2
  1. 创建独立程序:

    ¥Create the standalone program:

npx boxednode@2.4.3 -s xlsx-cli.js -t xlsx-cli

上次在 linux-arm 中测试此演示时,构建失败并显示错误:

¥When this demo was last tested in linux-arm, the build failed with an error:

../deps/v8/src/base/small-vector.h: In instantiation of ‘class v8::base::SmallVector<std::pair<const v8::internal::compiler::turboshaft::PhiOp*, const v8::internal::compiler::turboshaft::OpIndex>, 16>’: ../deps/v8/src/compiler/turboshaft/loop-unrolling-reducer.h:444:11: required from here ../deps/v8/src/base/macros.h:206:55: error: static assertion failed: T should be trivially copyable 206 | static_assert(::v8::base::is_trivially_copyable<T>::value, \ | ^~~~~

这会影响 NodeJS 22.2.0,但不会影响 20.13.1。它会影响 V8 JavaScript 引擎

¥This affects NodeJS 22.2.0, but does not affect 20.13.1. It affects the V8 JavaScript Engine.

-n 标志控制目标 NodeJS 版本。对于此演示,以下命令使用 NodeJS 20.13.1

¥The -n flag controls the target NodeJS version. For this demo, the following command uses NodeJS 20.13.1:

npx boxednode@2.4.3 -s xlsx-cli.js -t xlsx-cli -n 20.13.1
  1. 运行生成的程序,将 pres.numbers 作为参数传递:

    ¥Run the generated program, passing pres.numbers as the argument:

./xlsx-cli pres.numbers

[^1]: 该项目没有网站。源存储库 是公开可用的。

¥The project does not have a website. The source repository is publicly available.

[^2]: 下载可以找到 在 NASM 项目主网站上

¥Downloads can be found at the main NASM project website