最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

Node.js 使用 officecrypto-tool 讀取加密的 Excel (xls, xlsx) 和 Word( docx)文檔, 還支持 xlsx 和 docx 文件的加密(具體使用看文檔)。暫時(shí)不支持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

// 其實(shí) node-xlsx 只是對(duì)xlsx 進(jìn)行了封裝,里面還是調(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 解密以后再用對(duì)應(yīng)的庫去處理

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

相關(guān)文章

  • Node.js安裝及npm國內(nèi)鏡像配置的方法實(shí)現(xiàn)

    Node.js安裝及npm國內(nèi)鏡像配置的方法實(shí)現(xiàn)

    本文主要介紹了Node.js安裝及npm國內(nèi)鏡像配置,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • 詳解nodejs微信公眾號(hào)開發(fā)——6.自定義菜單

    詳解nodejs微信公眾號(hào)開發(fā)——6.自定義菜單

    這篇文章主要介紹了詳解nodejs微信公眾號(hào)開發(fā)——6.自定義菜單,自定義菜單能夠幫助公眾號(hào)豐富界面,讓用戶更好更快地理解公眾號(hào)的功能。
    2017-04-04
  • node+axios實(shí)現(xiàn)服務(wù)端文件上傳示例

    node+axios實(shí)現(xiàn)服務(wù)端文件上傳示例

    這篇文章主要介紹了node+axios實(shí)現(xiàn)服務(wù)端文件上傳示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • node指定內(nèi)存上限簡單代碼實(shí)例

    node指定內(nèi)存上限簡單代碼實(shí)例

    NodeJS啟動(dòng)的應(yīng)用,內(nèi)存使用是有上限的,下面這篇文章主要給大家介紹了關(guān)于node指定內(nèi)存上限的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • 淺談手寫node可讀流之流動(dòng)模式

    淺談手寫node可讀流之流動(dòng)模式

    這篇文章主要介紹了淺談手寫node可讀流之流動(dòng)模式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • nodejs+express最簡易的連接數(shù)據(jù)庫的方法

    nodejs+express最簡易的連接數(shù)據(jù)庫的方法

    這篇文章主要介紹了nodejs+express 最簡易的連接數(shù)據(jù)庫,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Node.js服務(wù)器開啟Gzip壓縮教程

    Node.js服務(wù)器開啟Gzip壓縮教程

    開啟網(wǎng)站的 gzip 壓縮功能,通??梢愿哌_(dá)70%,也就是說,如果你的網(wǎng)頁有30K,壓縮之后就變成9K, 對(duì)于大部分網(wǎng)站,顯然可以明顯提高瀏覽速度(注:需要瀏覽器支持)。
    2017-08-08
  • 把Node.js程序加入服務(wù)實(shí)現(xiàn)隨機(jī)啟動(dòng)

    把Node.js程序加入服務(wù)實(shí)現(xiàn)隨機(jī)啟動(dòng)

    這篇文章主要介紹了把Node.js程序加入服務(wù)實(shí)現(xiàn)隨機(jī)啟動(dòng),本文使用qckwinsvc實(shí)現(xiàn)這個(gè)需求,講解了qckwinsvc的安裝和使用,需要的朋友可以參考下
    2015-06-06
  • Nodejs實(shí)現(xiàn)的操作MongoDB數(shù)據(jù)庫功能完整示例

    Nodejs實(shí)現(xiàn)的操作MongoDB數(shù)據(jù)庫功能完整示例

    這篇文章主要介紹了Nodejs實(shí)現(xiàn)的操作MongoDB數(shù)據(jù)庫功能,結(jié)合完整實(shí)例形式分析了nodejs針對(duì)MongoDB數(shù)據(jù)庫的連接及增刪改查基本操作技巧,需要的朋友可以參考下
    2019-02-02
  • node-sass安裝失敗的原因與解決方法

    node-sass安裝失敗的原因與解決方法

    這篇文章主要給大家介紹了關(guān)于node-sass安裝失敗的原因與解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-09-09

最新評(píng)論

勐海县| 屯门区| 竹北市| 丹阳市| 阿城市| 平泉县| 高邑县| 遵义县| 交城县| 黔江区| 海原县| 白水县| 中江县| 邢台县| 康定县| 英超| 郸城县| 临夏县| 花垣县| 绥阳县| 澳门| 盐津县| 白河县| 桃园县| 玛沁县| 上犹县| 航空| 呈贡县| 米脂县| 兰坪| 桐城市| 香格里拉县| 龙川县| 象山县| 定边县| 河曲县| 黔西| 满洲里市| 泽普县| 保定市| 大埔县|