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(文 ...
随机推荐
- 从源码级深入剖析Tomcat类加载原理
众所周知,Java中默认的类加载器是以父子关系存在的,实现了双亲委派机制进行类的加载,在前文中,我们提到了,双亲委派机制的设计是为了保证类的唯一性,这意味着在同一个JVM中是不能加载相同类库的不同版本 ...
- CSS3实现嵌套立方体旋转的3D效果
刚发现一个网站上面的3D立方体效果挺好看的,就模仿着用CSS3实现了一个类似的效果:http://39.105.101.122/myhtml/CSS/transform_3D/cube_3D.html ...
- PyTorch与机器学习中的随机化:减少噪声和随机性
目录 2.1 基本概念解释 2.2 技术原理介绍 2.3 相关技术比较 3. 实现步骤与流程 3.1 准备工作:环境配置与依赖安装 3.2 核心模块实现 3.3 集成与测试 4. 应用示例与代码实现讲 ...
- mysql 查询时间段的数据怎么写?
测试让我查询2个时间段的数据,这里不怎么会,所以记录一下: 一般可以使用如下语法: select * from xxx表 where xx='xx' and time between '时间戳' ...
- Java 写一个线程安全的单例模式(饱汉/饿汉)
饿汉单例 public class Singleton { private static Singleton singleton = new Singleton(); private Singleto ...
- Unity的Console的控制类LogEntries:深入解析与实用案例
使用Unity Console窗口的LogEntries私有类实现自定义日志系统 在Unity开发过程中,我们经常需要使用Console窗口来查看程序运行时的日志信息.Unity内置的日志系统提供了基 ...
- 【项目学习】ERC-4337 抽象账户项目审计过程中需要注意的安全问题
抽象账户是什么 抽象账户(也有叫合约钱包)是 EIP-4337 提案提出的一个标准.简单来说就是通过智能合约来实现一个"账户(account)",在合约中自行实现签名验证的逻辑.这 ...
- 本地数据local storage和session storage
随着互联网的快速发展,基于网页的应用越来越普遍,同时也变的越来越复杂,为了满足各种各样的需求,会经常性在本地存储大量的数据, HTML5规范提出了相关解决方案. 本地存储特性 1.数据存储在用户浏览器 ...
- Federated Learning003
联邦学习笔记--003 2022.11.28周一 今天主要学习了几篇优秀的博客,补充了一些知识. (一)联邦学习面临的挑战 非独立同分布的数据 有限通信带宽 不可靠和有限的设备 什么是Non-IID( ...
- List子集合__小记
List集合的子实现类的特点: ArrayList: 底层数据结构是数组的形式,满足数组结构的特点:查询快,增删慢 从线程安全问题来看:线程不安全的,不同步,执行效率高 Vector: 底层数据结构是 ...