使用 Jurassic 在 .NET 中创建工作表
Jurassic[^1] 是 .NET 的 JavaScript 编译器,与其他引擎不同,Jurassic 生成 .NET 字节码。
¥Jurassic[^1] is a JavaScript compiler for .NET, In contrast to other engines, Jurassic generates .NET bytecode.
SheetJS 是一个用于从电子表格读取和写入数据的 JavaScript 库。
¥SheetJS is a JavaScript library for reading and writing data from spreadsheets.
此演示使用 Jurassic 和 SheetJS 读取和写入电子表格。我们将探索如何在 Jurassic 引擎中加载 SheetJS、与 C# 程序交换二进制数据以及处理电子表格和结构化数据。
¥This demo uses Jurassic and SheetJS to read and write spreadsheets. We'll explore how to load SheetJS in the Jurassic engine, exchange binary data with a C# program, and process spreadsheets and structured data.
"集成示例" 部分包含一个完整的命令行工具,用于读取任意工作簿并将数据写入 ODS(开放文档电子表格)工作簿。
¥The "Integration Example" section includes a complete command-line tool for reading arbitrary workbooks and writing data to ODS (OpenDocument Spreadsheet) workbooks.
dotnet
命令嵌入遥测技术。
¥The dotnet
command embeds telemetry.
DOTNET_CLI_TELEMETRY_OPTOUT
环境变量应设置为 1
。
¥The DOTNET_CLI_TELEMETRY_OPTOUT
environment variable should be set to 1
.
"平台配置" 包含有关在支持的平台上设置环境变量的说明。
¥"Platform Configuration" includes instructions for setting the environment variable on supported platforms.
集成详情
¥Integration Details
SheetJS "mini" 脚本 可以在 Jurassic 引擎实例中解析和评估。
¥The SheetJS "mini" script can be parsed and evaluated in a Jurassic engine instance.
Jurassic 在处理 "full" 脚本(xlsx.full.min.js
)时会抛出错误:
¥Jurassic throws errors when processing the "full" script (xlsx.full.min.js
):
Unhandled exception. Jurassic.JavaScriptException: Error: Maximum number of named properties reached.
必须使用 xlsx.mini.min.js
脚本!
¥The xlsx.mini.min.js
script must be used!
迷你版本有许多限制,如安装指南中所述。
¥The mini build has a number of limitations, as noted in the installation guide.
建议在 C# 代码和脚本引擎之间传递 Base64 字符串。
¥It is recommended to pass Base64 strings between C# code and the script engine.