Node.js 使用 officecrypto-tool 读取加密的 Excel (xls, xlsx) 和 Word( docx)文档
Node.js 使用 officecrypto-tool 读取加密的 Excel (xls, xlsx) 和 Word( docx)文档, 还支持 xlsx 和 docx 文件的加密(具体使用看文档)。暂时不支持doc文件的解密
读取加密的 Excel 示例
一:xlsx-populate
// 只支持 xlsx, xlsx-populate 自带了解密功能,
// 不过只支持 ecma376 agile 模式,也就是Office 生成的加密的docx,
// WPS的就不行, WPS用的是 ecma376 standard 模式
const XlsxPopulate = require('xlsx-populate');
(async ()=>{
const input = await fs.readFile(`pass_test.xlsx`);
const output = await officeCrypto.decrypt(input, {password: '123456'});
const workbook = await XlsxPopulate.fromDataAsync(output);
// 或者可先判断文件是否是加密的
const isEncrypted = officeCrypto.isEncrypted(input);
let output = input;
if (isEncrypted) {
output = await officeCrypto.decrypt(input, {password: '123456'});
}
const workbook = await XlsxPopulate.fromDataAsync(output);
})()
二:@zurmokeeper/exceljs https://www.npmjs.com/package/@zurmokeeper/exceljs
// 只支持 xlsx @zurmokeeper/exceljs 直接内置了解密功能,完全兼容exceljs v4.3.0
const Excel = require('@zurmokeeper/exceljs');
(async ()=>{
// 从文件读取, 解密使用密码加密的excel文件
const workbook = new Excel.Workbook();
await workbook.xlsx.readFile(filename, {password:'123456'});
// 从流读取, 解密使用密码加密的excel文件
const workbook = new Excel.Workbook();
await workbook.xlsx.read(stream, {password:'123456'});
// 从 buffer 加载, 解密使用密码加密的excel文件
const workbook = new Excel.Workbook();
await workbook.xlsx.load(data, {password:'123456'});
})()
三:xlsx
// xlsx 支持 xls 和 xlsx
const XLSX = require('xlsx');
(async ()=>{
const input = await fs.readFile(`pass_test.xlsx`);
// const input = await fs.readFile(`pass_test.xls`); // 或者xls
const output = await officeCrypto.decrypt(input, {password: '123456'});
const workbook = XLSX.read(output);
// 或者可先判断文件是否是加密的
const isEncrypted = officeCrypto.isEncrypted(input);
let output = input;
if (isEncrypted) {
output = await officeCrypto.decrypt(input, {password: '123456'});
}
const workbook = XLSX.read(output);
})()
四:node-xlsx
// 其实 node-xlsx 只是对xlsx 进行了封装,里面还是调用 xlsx 去解析的
const nodeXlsx = require('node-xlsx');
(async ()=>{
const input = await fs.readFile(`pass_test.xlsx`);
// const input = await fs.readFile(`pass_test.xls`); // 或者xls
const output = await officeCrypto.decrypt(input, {password: '123456'});
const workbook = nodeXlsx.parse(output);
// 或者可先判断文件是否是加密的
const isEncrypted = officeCrypto.isEncrypted(input);
let output = input;
if (isEncrypted) {
output = await officeCrypto.decrypt(input, {password: '123456'});
}
const workbook = nodeXlsx.parse(output);
})()
读取加密的 Word 示例
const officeCrypto = require('officecrypto-tool');
const fs = require('fs').promises;
const mammoth = require('mammoth');
(async ()=>{
const input = await fs.readFile(`pass_test.xlsx`);
const output = await officeCrypto.decrypt(input, {password: '123456'});
await mammoth.convertToHtml({buffer: output});
// 或者可先判断文件是否是加密的
const isEncrypted = officeCrypto.isEncrypted(input);
let output = input;
if (isEncrypted) {
output = await officeCrypto.decrypt(input, {password: '123456'});
}
await mammoth.convertToHtml({buffer: output});
})()
使用其他的word读取库也是一样的道理,先使用 officecrypto-tool 解密以后再用对应的库去处理
Node.js 使用 officecrypto-tool 读取加密的 Excel (xls, xlsx) 和 Word( docx)文档的更多相关文章
- 【node.js】readline (逐行读取)
官网链接:http://nodejs.cn/api/readline#readline_readline require('readline') 模块提供了一个接口,用于从可读流(如 process. ...
- 使用node.js的bodyParser中间件读取post数据解析
昨天我们使用的网关转发数据时出了点问题! 情景是这样的,另一方以Post的形式向我的node.js服务推送JSON数据.但是使用bodyParser中间件后,在req.body中拿不到任何信息. 代码 ...
- electron node.js 实现文件拖动读取文件
css/styles.css .for_file_drop { width: 100%; height: 100px; background-color: blueviolet; } index.ht ...
- php创建读取 word.doc文档
创建文档; <?php $html = "this is question"; for($i=1;$i<=3;$i++){ $word = new word(); $w ...
- MVC架构下,使用NPOI读取.DOCX文档中表格的内容
1.使用NPOI,可以在没有安装office的设备上读wiod.office.2.本文只能读取.docx后缀的文档.3.MVC架构中,上传文件只能使用form表单提交,转到控制器后要依次实现文件上传. ...
- c# 读取 excel文件内容,写入txt文档
1 winform 读取excel文档 1)点击button按钮,弹出上传excel窗口 private void button_headcompany_Click(object sender, Ev ...
- node.js中用户密码的加密
crypro实现用户密码的加密 在实际的项目中,只要涉及到用户的信息,就是十分重要的.设想一下数据库里面存放的用户的密码是明文的形式,后果是有多严重.所以今天给大家分享一下express中怎样实现用户 ...
- 转 node.js和 android中java加密解密一致性问题;
原文地址,请大家去原文博客了解; http://blog.csdn.net/linminqin/article/details/19972751 我保留一份,防止删除: var crypto = re ...
- 【Node.js】'readline' 逐行读取、写入文件内容
[转]运用readline逐行读取的两种实现 效果图如下: 左边1.log 为源文件 右边1.readline.log为复制后的文件 下边为命令行输出 实现方式一: [javascript] view ...
- VBA 读取加密的Excel文件(VBA 加密Excel)
实验成功的: ExcelApp.Workbooks.Open(文件路径,,,'密码') 这里很坑,搜了别人的博客,下面这个方法试了N次,都没用... ExcelApp.Workbooks.Open(文 ...
随机推荐
- 2021年蓝桥杯C/C++大学B组省赛真题(路径)
题目描述: 小蓝学习了最短路径之后特别高兴,他定义了一个特别的图,希望找到图中的最短路径. 小蓝的图由2021 个结点组成,依次编号1 至2021. 对于两个不同的结点a, b,如果a 和b 的差的绝 ...
- 文件系统考古:1974-Unix V7 File System
有时,进步难以察觉,特别是当你正身处其中时.而对比新旧资料之间的差异,寻找那些推动变革的信息源,我们就可以清晰地看到进步的发生.在Linux(以及大部分Unix系统)中,都可以印证这一点. Unix ...
- 使用git 将本地代码上传码市私用仓库操作
1 现在在登录码市建立项目 2 本地建立一个文件夹,然后使用git bash 3 初始化本地库 git init 4,进入刚刚在码云新建的项目里,复制框框里的路径 5,然后在回到本地新建的 ...
- 领福利 | 腾讯千帆HR数字化专场,教你数字时代的技术招聘秘笈
HR难,做技术招聘的HR难上加难 技术部门急需用人,收到的简历却寥寥无几? 推了简历,却被用人部门告知完全不合适? 候选人过了面试,却鸽了offer? 桥豆麻袋! 腾讯千帆联合ShowMeBug举办 ...
- C#.NET Framework RSA 公钥加密 私钥解密 ver:20230609
C#.NET Framework RSA 公钥加密 私钥解密 ver:20230609 环境说明: .NET Framework 4.6 的控制台程序 . .NET Framework 对于RSA的支 ...
- 分享6个SQL小技巧
原创:扣钉日记(微信公众号ID:codelogs),欢迎分享,非公众号转载保留此声明. 简介 经常有小哥发出疑问,SQL还能这么写?我经常笑着回应,SQL确实可以这么写.其实SQL学起来简单,用起来也 ...
- 设计 C++ 接口文件的小技巧之 PIMPL
设计 C++ 接口文件的小技巧之 PIMPL C++ 里面有一些惯用法(idioms),如 RAII,PIMPL,copy-swap.CRTP.SFINAE 等.今天要说的是 PIMPL,即 Poin ...
- [MAUI]弧形进度条与弧形滑块的交互实现
@ 目录 弧形基类 定义 绘制弧 弧形进度条(ProgressBar) 添加动画 宽度补偿 文本 弧形滑块(Slider) 创建控制柄 拖动事件处理 项目地址 进度条(ProgressBar)用于展示 ...
- 适合Windows桌面、Material Design设计风格、WPF美观控件库【强烈推荐】
推荐一个在Github已start超过13.6K,非常流行.美观的WPF控件库. 项目简介 这是一个适用于Windows桌面,全面且易于使用的控件库,遵循Google推测的Material Desig ...
- 让AI支持游戏制作流程:从游戏设计到发布一个完整的生态系统
目录 引言 随着游戏产业的快速发展,人工智能(AI)技术在游戏开发中的应用越来越广泛.游戏设计人员可以通过利用AI技术来自动化游戏中的某些流程,提高游戏制作的效率,降低开发成本,同时还可以创造出更加具 ...