使用 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-x64 | 2.4.0 | 22.2.0 | 2024-05-28 |
darwin-arm | 2.4.3 | 22.2.0 | 2024-05-25 |
win10-x64 | 2.4.2 | 16.20.2 | 2024-04-18 |
linux-x64 | 2.4.0 | 21.7.1 | 2024-03-21 |
linux-arm | 2.4.3 | 20.13.1 | 2024-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
-
下载测试文件 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
-
下载
xlsx-cli.js
¥Download
xlsx-cli.js
curl -o xlsx-cli.js https://xlsx.nodejs.cn/cli/xlsx-cli.js
-
安装依赖:
¥Install the dependencies:
- npm
- pnpm
- Yarn
npm i --save https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz exit-on-epipe commander@2
pnpm install --save https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz exit-on-epipe commander@2
yarn add https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz exit-on-epipe commander@2
-
创建独立程序:
¥Create the standalone program:
- Linux/MacOS
- Windows
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
npx boxednode@2.4.3 -s xlsx-cli.js -t xlsx-cli.exe -n 16.20.2
Windows 10 构建需要具有 "使用 C++ 进行桌面开发" 工作负载的 Visual Studio、Python 3.11 和 NASM[^2]。
¥The Windows 10 build requires Visual Studio with "Desktop development with C++" workload, Python 3.11, and NASM[^2].
构建命令必须在 "x64 原生工具命令提示符" 中运行
¥The build command must be run in "x64 Native Tools Command Prompt"
上次测试演示时,构建失败:
¥When the demo was last tested, the build failed:
Not an executable Python program
Could not find Python.
默认情况下,Windows 将 python
别名为 Microsoft Store 安装程序。如果使用官方安装程序,则应手动禁用别名:
¥By default, Windows aliases python
to a Microsoft Store installer. If the
official installer was used, the alias should be disabled manually:
-
打开“开始”菜单并输入 "应用别名"。单击 "管理应用执行别名"。
¥Open Start menu and type "app alias". Click "Manage app execution aliases".
-
禁用名称中包含
python
的所有项目的应用安装程序。¥Disable the App Installer for all items with
python
in the name.
使用 Python 3.12,构建失败并出现错误:
¥Using Python 3.12, the build fails with an error:
Please use python3.11 or python3.10 or python3.9 or python3.8 or python3.7 or python3.6.
在最近的测试中,Python 3.11.8 是从官方站点安装的。
¥In the most recent test, Python 3.11.8 was installed from the official site.
上次在 Windows 上测试演示时,构建失败:
¥When the demo was last tested on Windows, the build failed:
error MSB8020: The build tools for Visual Studio 2019 (Platform Toolset = 'v142') cannot be found. To build using the v142 build tools, please install Visual Studio 2019 build tools.
通过 Visual Studio 安装程序安装 v142
构建工具已修复此错误。
¥This error was fixed by installing the v142
build tools through the Visual
Studio installer.
在最近针对 NodeJS 20.8.0
的 Windows 测试中,由于 OpenSSL 依赖的问题,构建失败:
¥In the most recent Windows test against NodeJS 20.8.0
, the build failed due
to an issue in the OpenSSL dependency:
...\node-v20.8.0\deps\openssl\openssl\crypto\cversion.c(75,33): error C2153: integer literals must have at least one digit [...\node-v20.8.0\deps\openssl\openssl.vcxproj]
SheetJS 库与可追溯到 v0.8
的 NodeJS 版本兼容。解决方法是使用 -n
标志选择 NodeJS v16.20.2
。由于 NodeJS v18
升级了 OpenSSL 依赖,因此选择了该版本。
¥SheetJS libraries are compatible with NodeJS versions dating back to v0.8
. The
workaround is to select NodeJS v16.20.2
using the -n
flag. This version was
was chosen since NodeJS v18
upgraded the OpenSSL dependency.
-
运行生成的程序,将
pres.numbers
作为参数传递:¥Run the generated program, passing
pres.numbers
as the argument:
- Linux/MacOS
- Windows
./xlsx-cli pres.numbers
.\xlsx-cli.exe 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