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(文 ...
随机推荐
- Linux系统 2023年5月1号
今天正式进入了LINUX基础核心 下载了centos7.4镜像 和vmware12版本,还未安装vmware和centos镜像7.4
- 洛谷 P8742题解
简单版(P2347)传送门 原题传送门 有一道类似的题目(P2347),先扯一扯~ 1.P2347 题目分析 动态规划入门题(01背包可行性问题)~ 我们设 \(dp_j\) 为能否用砝码称出 \(j ...
- 烂怂if-else代码优化方案
0.问题概述 代码可读性是衡量代码质量的重要标准,可读性也是可维护性.可扩展性的保证,因为代码是连接程序员和机器的中间桥梁,要对双边友好.Quora 上有一个帖子: "What are so ...
- STL-set(ACM)
1.set只能insert().erase(),没有push()等操作 2.插入的元素自动排序按从小到大的顺序排 3.不会插入相同的元素,已经插入了6,之后就不会再插入了 4.时间复杂度为 O(log ...
- 做副业的我很迷茫,但ChatGPT却治好了我——AI从业者被AI模型治愈的故事
迷茫,无非就是不知道自己要做什么,没有目标,没有方向. 当有一个明确的目标时,往往干劲十足.但做副业过程中,最大的问题往往就是 不知道自己该干什么. 干什么?怎么干?干到什么程度?这是做副业(甚至任何 ...
- 文字生成图像 AI免费工具第二弹 DreamStudio
介绍Stable Diffution,就也要提一下DreamStudio,它是Stable Diffusion的母公司Stability AI开发的一个文字生成图像工具,邮箱注册后可以免费生成125张 ...
- 记一次 .NET 某药材管理系统 卡死分析
一:背景 1. 讲故事 前段时间有位朋友找到我,说他们在查询报表的时候发现程序的稳定性会受到影响,但服务器的内存,CPU都是正常的,让我帮忙看下怎么回事,问了下程序的稳定性指的是什么?指的是卡死,那既 ...
- Java Websocket 02: 原生模式通过 Websocket 传输文件
目录 Java Websocket 01: 原生模式 Websocket 基础通信 Java Websocket 02: 原生模式通过 Websocket 传输文件 Websocket 原生模式 传输 ...
- Taurus .Net Core 微服务开源框架:Admin 插件【2】 - 系统环境信息管理
前言: 继上篇:Taurus .Net Core 微服务开源框架:Admin 插件[1] - 微服务节点管理 本篇继续介绍下一个内容: 1.系统环境信息节点 - OS-Environment 界面 基 ...
- 记一次 .NET 某企业采购平台 崩溃分析
一:背景 1. 讲故事 前段时间有个朋友找到我,说他们的程序有偶发崩溃的情况,让我帮忙看下怎么回事,针对这种 crash 的程序,用 AEDebug 的方式抓取一个便知,有了 dump 之后接下来就可 ...