使用 Nexe 的电子表格工具
nexe
[^1] 是一种用于生成嵌入脚本的命令行工具的工具。
¥nexe
[^1] is a tool for generating command-line tools that embed scripts.
SheetJS 是一个用于从电子表格读取和写入数据的 JavaScript 库。
¥SheetJS is a JavaScript library for reading and writing data from spreadsheets.
此演示使用 nexe
和 SheetJS 创建独立的 CLI 工具,用于解析电子表格并转换为其他格式。
¥This demo uses nexe
and SheetJS to create a standalone CLI tool for parsing
spreadsheets and converting to other formats.
最新的预构建包与 NodeJS 版本 14.15.3
匹配。
¥The latest prebuilt package matches NodeJS version 14.15.3
.
nexe
可以为较新的 NodeJS 版本构建所需的包。
¥nexe
can build the required packages for newer NodeJS versions.
该演示在以下部署中进行了测试:
¥This demo was tested in the following deployments:
架构 | 版本 | NodeJS | 来源 | 日期 |
---|---|---|---|---|
darwin-x64 | 4.0.0-rc.6 | 14.15.3 | 预建 | 2025-01-19 |
darwin-arm | 4.0.0-rc.6 | 20.18.0 | 已编译 | 2025-02-13 |
win11-x64 | 4.0.0-rc.6 | 14.15.3 | 预建 | 2024-12-19 |
win11-arm | 4.0.0-rc.6 | 22.14.0 | 已编译 | 2025-02-23 |
linux-x64 | 4.0.0-rc.6 | 14.15.3 | 预建 | 2024-12-31 |
linux-arm | 4.0.0-rc.6 | 22.13.0 | 已编译 | 2025-02-15 |
集成详情
¥Integration Details
SheetJS NodeJS 模块 可以从脚本中需要。nexe
将自动处理打包。
¥The SheetJS NodeJS module can be
required from scripts. nexe
will automatically handle packaging.
脚本要求
¥Script Requirements
专门使用 SheetJS 库和 NodeJS 内置模块的脚本可以使用 nexe
进行打包。
¥Scripts that exclusively use SheetJS libraries and NodeJS built-in modules can
be bundled using nexe
.
演示脚本 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:
npx -y nexe -t 14.15.3 xlsx-cli.js
Building from source (click to hide)
当在 ARM 目标上测试演示时,Nexe 预构建包丢失。对于不受支持的 NodeJS 版本,必须从源代码构建包:
¥When the demo was tested on ARM targets, the Nexe pre-built packages were missing. For unsupported NodeJS versions, packages must be built from source:
- Linux/MacOS
- Windows
npx -y nexe xlsx-cli.js --build --python=$(which python3) --make="-j8"
在 Windows x64 上,--build
标志就足够了:
¥On Windows x64, the --build
flag suffices:
npx -y nexe xlsx-cli.js --build --make="-j8"
在 Windows ARM 上,必须指定目标 windows-arm64-22.14.0
,并且必须在 "原生工具命令提示符" 中运行命令:
¥On Windows ARM, the target windows-arm64-22.14.0
must be specified and the
command must be run in a "Native Tools Command Prompt":
npx -y nexe xlsx-cli.js --build --make="-j8" --target=windows-arm64-22.14.0
vcbuild.bat
问题
¥vcbuild.bat
issues
Windows ARM 构建可能会因 vcbuild.bat
错误而失败:
¥The Windows ARM build may fail with a vcbuild.bat
error:
Error: vcbuild.bat nosign release arm64 exited with code: 1
传递 --verbose
标志以获取更多详细信息:
¥Pass the --verbose
flag for more details:
npx -y nexe xlsx-cli.js --build --make="-j8" --target=windows-arm64-22.14.0 --verbose
常见错误信息:
¥Common error messages:
"未找到 Python"
¥"Python was not found"
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
开箱即用,Windows 11 将别名 python
,将毫无戒心的用户重定向到应用安装程序。必须禁用此重定向:
¥Out of the box, Windows 11 will alias python
, redirecting unsuspecting users
to the App Installer. This redirect must be disabled:
在搜索栏中输入 alias
并选择 "管理应用执行别名",在设置窗格中,向下滚动并关闭 python.exe
的别名。
¥Type alias
in the search bar and select "Manage app execution aliases", In the
settings pane, scroll down and turn off the alias for python.exe
.
"找不到 Python"
¥"Could not find Python"
Could not find Python.
使用官方安装程序安装 Python 后,应在新终端窗口中运行该命令。
¥After installing Python using the official installer, the command should be run in a new terminal window.
Python 版本不匹配 ("请使用")
¥Python version mismatch ("Please use")
Node.js configure: found Python 2.7.18
Please use python3.11 or python3.10 or python3.9 or python3.8 or python3.7 or python3.6
可以通过以下方式找到已解决的 Python 版本
¥The resolved version of Python can be found with
where python
在某些测试中,首先出现 Python 2 版本。通过查找 Python 3 位置并将其添加到 PATH
前面可以修复此问题:
¥In some tests, a Python 2 version appeared first. This was fixed by finding the
Python 3 location and prepending it to PATH
:
set PATH="C:\correct\path\to\python\three";%PATH%
这会根据平台生成 xlsx-cli
或 xlsx-cli.exe
。
¥This generates xlsx-cli
or xlsx-cli.exe
depending on platform.
-
运行生成的程序,将
pres.numbers
作为参数传递:¥Run the generated program, passing
pres.numbers
as the argument:
- Linux/MacOS
- Windows
./xlsx-cli pres.numbers
.\xlsx-cli.exe pres.numbers
程序应显示第一张表的 CSV 内容:
¥The program should display CSV contents from the first sheet:
Name,Index
Bill Clinton,42
GeorgeW Bush,43
Barack Obama,44
Donald Trump,45
Joseph Biden,46
[^1]: 该项目没有网站。源存储库 是公开可用的。
¥The project does not have a website. The source repository is publicly available.
[^2]: NodeJS 网站托管 预构建安装程序。
¥The NodeJS website hosts prebuilt installers.