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(文 ...
随机推荐
- Netty实战(三)
目录 一.Channel.EventLoop 和 ChannelFuture 1.1 Channel 接口 1.2 EventLoop 接口 1.3 ChannelFuture 接口 二.Channe ...
- 提高生产力的最佳免费开源终端:WindTerm
哈喽,大家好!我是程序视点的小二哥! 前言 自从当上程序员以来使用频率最多的不是vscode,也不是github,而是终端!!! 小师妹使用过很多的终端工具,什么Tabby,Putty,Wrap等等, ...
- deepin系统更新谷歌浏览器chrome的方法
deepin系统更新谷歌浏览器chrome的方法 1 为什么要更新谷歌浏览器谷歌浏览器更新频繁,隔一段时间不更新,打开浏览器时会自动弹出一个提示更新的窗口,有点烦,如果使用python自动处理程序时, ...
- 为什么 Biopython 的在线 BLAST 这么慢?
用过网页版本 BLAST 的童鞋都会发现,提交的序列比对往往在几分钟,甚至几十秒就可以得到比对的结果:而通过调用 API 却要花费几十分钟或者更长的时间!这到底是为什么呢? NCBIWWW 基本用法 ...
- 使用c#实现23种常见的设计模式
使用c#实现23种常见的设计模式 设计模式通常分为三个主要类别: 创建型模式 结构型模式 行为型模式. 这些模式是用于解决常见的对象导向设计问题的最佳实践. 以下是23种常见的设计模式并且提供c#代码 ...
- 案例实践 | 某能源企业API安全实践
随着智能电网.全球能源互联网."互联网+电力".新电改的全面实施,分布式能源.新能源.电力交易.智能用电等新型业务不断涌现,运营模式.用户群体都将发生较大变化,电力市场由相对专业向 ...
- ChatGPT的原理与前端领域实践
一.ChatGPT 简介 ChatGPT的火爆 ChatGPT作为一个web应用,自22年12月发布,仅仅不到3个月的时间,月活用户就累积到1亿.在此之前,最快记录的保持者也需要9个月才达到月活1亿. ...
- 使用Python实现学生信息管理系统
本文介绍了一个简单的学生信息管理系统,包括管理员登录.重置学生密码.添加.删除和修改学生信息.查询学生信息以及对学生成绩进行排序等功能.该系统使用Python编写,基于控制台交互 实现思路 该系统分为 ...
- 认识Dubbo与RPC
关注王有志,分享硬核Java技术的互金摸鱼侠 加入Java人的提桶跑路群:共同富裕的Java人 开个新坑,和大家一起学习Dubbo 3.X.我们按照一个由浅入深顺序来学习,先从使用Dubbo开始,再深 ...
- CSS_相关问题及解决_持续更新
css_margin塌陷问题 问题描述 <div class="father"> <div class="child1"></di ...