亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Node.js使用officecrypto-tool實現(xiàn)讀取加密的Excel和Word文檔

 更新時間:2023年09月06日 09:32:14   作者:神話  
這篇文章主要為大家詳細介紹了Node.js如何使用officecrypto-tool實現(xiàn)讀取加密的Excel和Word文檔的功能,感興趣的小伙伴可以跟隨小編一起了解一下

Node.js 使用 officecrypto-tool 讀取加密的 Excel (xls, xlsx) 和 Word( docx)文檔, 還支持 xlsx 和 docx 文件的加密(具體使用看文檔)。暫時不支持doc文件的解密

傳送門:officecrypto-tool

讀取加密的 Excel 示例

1.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);
 })()

2.@zurmokeeper/exceljs

https://www.npmjs.com/package/@zurmokeeper/exceljs

// 只支持 xlsx @zurmokeeper/exceljs 直接內(nèi)置了解密功能,完全兼容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'});
})()

3.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);
})()

4.node-xlsx

// 其實 node-xlsx 只是對xlsx 進行了封裝,里面還是調(diào)用 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 示例

使用:mammoth officecrypto-tool

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 解密以后再用對應(yīng)的庫去處理

到此這篇關(guān)于Node.js使用officecrypto-tool實現(xiàn)讀取加密的Excel和Word文檔的文章就介紹到這了,更多相關(guān)Node.js讀取加密文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • nodejs語言實現(xiàn)驗證碼生成功能的示例代碼

    nodejs語言實現(xiàn)驗證碼生成功能的示例代碼

    這篇文章主要介紹了nodejs語言實現(xiàn)驗證碼生成功能的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • nodejs npm錯誤Error:UNKNOWN:unknown error,mkdir ''D:\Develop\nodejs\node_global''at Error

    nodejs npm錯誤Error:UNKNOWN:unknown error,mkdir ''D:\Develop\n

    今天小編就為大家分享一篇關(guān)于nodejs npm錯誤Error:UNKNOWN:unknown error,mkdir 'D:\Develop\nodejs\node_global'at Error,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Nodejs中Express 常用中間件 body-parser 實現(xiàn)解析

    Nodejs中Express 常用中間件 body-parser 實現(xiàn)解析

    這篇文章主要介紹了Nodejs中Express 常用中間件 body-parser 實現(xiàn)解析,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Nodejs使用fs-extra模塊進行目錄和文件操作用法示例

    Nodejs使用fs-extra模塊進行目錄和文件操作用法示例

    fs-extra模塊是基于fs?的文件操作相關(guān)工具庫,封裝了一些fs實現(xiàn)起來相對復(fù)雜的工具,下面這篇文章主要給大家介紹了關(guān)于Nodejs使用fs-extra模塊進行目錄和文件操作用法的相關(guān)資料,需要的朋友可以參考下
    2024-06-06
  • 淺談node使用jwt生成的token應(yīng)該存在哪里

    淺談node使用jwt生成的token應(yīng)該存在哪里

    早上逛某乎的時候,遇到一位同學(xué)在問這個問題,很好奇jwt的存儲位置。本文詳細的介紹一下,感興趣的可以了解一下
    2021-06-06
  • 如何在命令行判斷node.js啟動了沒有(最新)

    如何在命令行判斷node.js啟動了沒有(最新)

    這篇文章主要介紹了如何在命令行判斷node.js啟動了沒有,使用 tasklist 命令列出所有正在運行的進程,并使用 findstr 命令過濾出 Node.js 進程,感興趣的朋友跟隨小編一起看看吧
    2024-06-06
  • Node.js之HTTP服務(wù)端和客戶端實現(xiàn)方式

    Node.js之HTTP服務(wù)端和客戶端實現(xiàn)方式

    這篇文章主要介紹了Node.js之HTTP服務(wù)端和客戶端實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-09-09
  • npm下載慢或下載失敗問題解決的三種方法

    npm下載慢或下載失敗問題解決的三種方法

    這篇文章主要為大家介紹了npm下載慢或下載失敗問題解決的三種方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • 詳解使用Node.js 將txt文件轉(zhuǎn)為Excel文件

    詳解使用Node.js 將txt文件轉(zhuǎn)為Excel文件

    這篇文章主要介紹了詳解使用Node.js 將txt文件轉(zhuǎn)為Excel文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Node.js打包管理工具NPM用法

    Node.js打包管理工具NPM用法

    這篇文章介紹了Node.js打包管理工具NPM的用法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04

最新評論