officecrypto-tool

officecrypto-tool 是一个 JavaScript 库,用于对 Office 文件(Excel、PPT、Word)进行加解密操作。支持多种文件格式的加解密,API 设计简单易用,兼容 WPS 和 MS Office。

介绍officecrypto-tool 是一个 JS 库,用于 office 文件(excel/ppt/word)的加解密。支持excel(xls(x)),word(doc(x)),ppt(ppt(x)) 文件的解密,支持 xlsx,docx,pptx 格式的加密。受 xlsxxlsx-populate, 的启发,API 设计也很简单,加解密导出的文件,支持WPS 和 MS Office 打开。## 安装npm/yarn/pnpm install officecrypto-tool## 示例const officeCrypto = require('officecrypto-tool');const fs = require('fs').promises;// 解密一个带密码加密的文件(async ()=>{ const input = await fs.readFile(`pass_test.xlsx`); const output = await officeCrypto.decrypt(input, {password: '123456'}); await fs.writeFile(`out_success.xlsx`, output);})()// 使用密码加密一个文件(async ()=>{ const input = await fs.readFile(`test.xlsx`); const output = officeCrypto.encrypt(input, {password: '123456'}); await fs.writeFile(`standard_out_success.xlsx`, output);})()// 提供 isEncrypted API 判断一个文件是否是加密的,支持所有类型(async ()=>{ const input = await fs.readFile(`encrypted_test.xlsx`); const isEncrypted = officeCrypto.isEncrypted(input); // output: true const input1 = await fs.readFile(`not_encrypted_test.xlsx`); const isEncrypted1 = officeCrypto.isEncrypted(input1); // output: false})()## 相关链接- GitHub 仓库- NPM 链接- 更多详细教程和示例