ExcelJS庫的使用

ExcelJS

安裝

npm install exceljs

新的功能!

  • Merged fix: styles rendering in case when “numFmt” is present in conditional formatting rules (resolves #1814) #1815.
    Many thanks to @andreykrupskii for this contribution!
  • Merged inlineStr cell type support #1575 #1576.
    Many thanks to @drdmitry for this contribution!
  • Merged Fix parsing of boolean attributes #1849.
    Many thanks to @bno1 for this contribution!
  • Merged add optional custom auto-filter to table #1670.
    Many thanks to @thambley for this contribution!
  • Merged Deep copy inherited style #1850.
    Many thanks to @ikzhr for this contribution!
  • Merged Upgrade actions/cache and actions/setup-node #1846.
    Many thanks to @cclauss for this contribution!
  • Merged Check object keys in isEqual #1831.
    Many thanks to @bno1 for this contribution!
  • Merged Add v17 to testing workflow #1856.
    Many thanks to @Siemienik for this contribution!
  • Merged Upgrade jszip to its latest version to date. This version does not have any vulnerability found by Snyk so far #1895.
    Many thanks to @ValerioSevilla for this contribution!
  • Merged Update README.md #1677.
    Many thanks to @xjrcode for this contribution!
  • Merged (docs): set prototype of RegExp correctly. #1700.
    Many thanks to @joeldenning for this contribution!
  • Merged Added timeouts to github actions #1733.
    Many thanks to @alexbjorlig for this contribution!
  • Merged fix issue 1676 #1701.
    Many thanks to @skypesky for this contribution!
  • Merged ExcelJS/ExcelJS#2237 : Update CI Tests, Drop support for Node v8 #2242.
    Many thanks to @Siemienik for this contribution!
  • Merged Fix types for getWorksheet() #2223.
    Many thanks to @hfhchan-plb for this contribution!
  • Merged add characters cannot be used for worksheet name #2126.
    Many thanks to @tkm-kj for this contribution!
  • Merged Fix issue #1753 Reject promise when workbook reader is writing to temporary file stream and error occurs #1756.
    Many thanks to @pauliusg for this contribution!
  • Merged README.md to have correct link for Streaming XLSX #2186.
    Many thanks to @wulfsolter for this contribution!
  • Merged Added a polyfill of promise.finally to support lower versions of Firefox. #1982.
    Many thanks to @DemoJj for this contribution!
  • Merged Fix read this.worksheet before assign it #1934.
    Many thanks to @ZyqGitHub1 for this contribution!
  • Merged chore: upgrade jszip to ^3.10.1 #2211.
    Many thanks to @jarrod-cocoon for this contribution!
  • Merged fixed spelling error in README.md file #2208.
    Many thanks to @HugoP27 for this contribution!
  • Merged fix: Fix xlsx.writeFile() not catching error when error occurs #2244.
    Many thanks to @zurmokeeper for this contribution!
  • Merged Improve worksheets’ naming validation logic. #2257.
    Many thanks to @Siemienik for this contribution!
  • Merged fix issue 2125 - spliceRows remove last row #2140.
    Many thanks to @babu-ch for this contribution!
  • Merged fix: fix the loss of column attributes due to incorrect column order #2222.
    Many thanks to @cpaiyueyue for this contribution!
  • Merged Fix: Sheet Properties Types #2327.
    Many thanks to @albeniraouf for this contribution!
  • Merged Use node 18 LTS for tsc, and benchmark. Add node 20. to test matrix. … #2354.
    Many thanks to @Siemienik for this contribution!
  • Merged Add missing tooltip attribute to CellHyperlinkValue index.d.ts #2350.
    Many thanks to @NiklasPor for this contribution!
  • Merged Increase resilience to generating large workbooks #2320.
    Many thanks to @hfhchan-plb for this contribution!
  • Merged repair all ‘c2fo.io’ links (‘c2fo.github.io’) #2324.
    Many thanks to @justintunev7 for this contribution!
  • Merged fix: fix type definitions about last column, formula values and protection #2309.
    Many thanks to @gltjk for this contribution!
  • Merged fix: add spinCount field for WorksheetProtection type #2284.
    Many thanks to @damingerdai for this contribution!
  • Merged Add type definition for WorksheetModel.merges #2281.
    Many thanks to @ytjmt for this contribution!

貢獻

歡迎貢獻!這可以幫助我了解大家需要一些什么功能,或者哪些 bugs 造成了極大的麻煩。

我只有一個請求;如果您提交對錯誤修復的請求(PR),請添加一個能夠解決問題的單元測試或集成測試(在 spec 文件夾中)。
即使只是測試失敗的請求(PR)也可以 - 我可以分析測試的過程并以此修復代碼。

注意:請盡可能避免在請求(PR)中修改軟件包版本。
版本一般在發布時會進行更新,任何版本更改很可能導致合并沖突。

明確地說,添加到該庫的所有貢獻都將包含在該庫的 MIT 許可證中。

目錄

  • 導入
  • 接口
    • 創建工作簿
    • 設置工作簿屬性
    • 工作簿視圖
    • 添加工作表
    • 刪除工作表
    • 訪問工作表
    • 工作表狀態
    • 工作表屬性
    • 頁面設置
    • 頁眉和頁腳
    • 工作表視圖
      • 凍結視圖
      • 拆分視圖
    • 自動篩選器
      • Add Rows
      • 處理單個單元格
      • 合并單元格
      • Insert Rows
      • Splice
      • 重復行
    • 定義名稱
    • 數據驗證
    • 單元格注釋
    • 表格
    • 樣式
      • 數字格式
      • 字體
      • 對齊
      • 邊框
      • 填充
      • 富文本
    • 條件格式化
    • 大綱級別
    • 圖片
    • 工作表保護
    • 文件 I/O
      • XLSX
        • 讀 XLSX
        • 寫 XLSX
      • CSV
        • 讀 CSV
        • 寫 CSV
      • 流式 I/O
        • 流式 XLSX
  • 瀏覽器
  • 值類型
    • Null 值
    • 合并單元格
    • 數字值
    • 字符串值
    • 日期值
    • 超鏈接值
    • 公式值
      • 共享公式
      • 公式類型
      • 數組公式
    • 富文本值
    • 布爾值
    • 錯誤值
  • 配置
  • 已知的問題
  • 發布歷史

導入?

const ExcelJS = require('exceljs');

ES5 導入?

要使用 ES5 編譯代碼,請使用 dist/es5 路徑。

const ExcelJS = require('exceljs/dist/es5');

**注意:**ES5 版本對許多 polyfill 都具有隱式依賴,而 exceljs 不再明確添加。
您需要在依賴項中添加 core-jsregenerator-runtime,并在導入 exceljs 之前在代碼中包含以下引用:

// exceljs 所需的 polyfills
require('core-js/modules/es.promise');
require('core-js/modules/es.string.includes');
require('core-js/modules/es.object.assign');
require('core-js/modules/es.object.keys');
require('core-js/modules/es.symbol');
require('core-js/modules/es.symbol.async-iterator');
require('regenerator-runtime/runtime');const ExcelJS = require('exceljs/dist/es5');

對于 IE 11,您還需要一個 polyfill 以支持 unicode regex 模式。 例如,

const rewritePattern = require('regexpu-core');
const {generateRegexpuOptions} = require('@babel/helper-create-regexp-features-plugin/lib/util');const {RegExp} = global;
try {new RegExp('a', 'u');
} catch (err) {global.RegExp = function(pattern, flags) {if (flags && flags.includes('u')) {return new RegExp(rewritePattern(pattern, flags, generateRegexpuOptions({flags, pattern})));}return new RegExp(pattern, flags);};global.RegExp.prototype = RegExp.prototype;
}

瀏覽器端?

ExcelJS 在 dist/ 文件夾內發布了兩個支持瀏覽器的包:

一個是隱式依賴 core-js polyfills 的…

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.js"></script>
<script src="exceljs.js"></script>

另一個則沒有…

<script src="--your-project's-pollyfills-here--"></script>
<script src="exceljs.bare.js"></script>

接口?

創建工作簿?

const workbook = new ExcelJS.Workbook();

設置工作簿屬性?

workbook.creator = 'Me';
workbook.lastModifiedBy = 'Her';
workbook.created = new Date(1985, 8, 30);
workbook.modified = new Date();
workbook.lastPrinted = new Date(2016, 9, 27);
// 將工作簿日期設置為 1904 年日期系統
workbook.properties.date1904 = true;

設置計算屬性?

// 在加載時強制工作簿計算屬性
workbook.calcProperties.fullCalcOnLoad = true;

工作簿視圖?

工作簿視圖控制在查看工作簿時 Excel 將打開多少個單獨的窗口。

workbook.views = [{x: 0, y: 0, width: 10000, height: 20000,firstSheet: 0, activeTab: 1, visibility: 'visible'}
]

添加工作表?

const sheet = workbook.addWorksheet('My Sheet');

使用 addWorksheet 函數的第二個參數來指定工作表的選項。

示例:

// 創建帶有紅色標簽顏色的工作表
const sheet = workbook.addWorksheet('My Sheet', {properties:{tabColor:{argb:'FFC0000'}}});// 創建一個隱藏了網格線的工作表
const sheet = workbook.addWorksheet('My Sheet', {views: [{showGridLines: false}]});// 創建一個第一行和列凍結的工作表
const sheet = workbook.addWorksheet('My Sheet', {views:[{xSplit: 1, ySplit:1}]});// 使用A4設置的頁面設置設置創建新工作表 - 橫向
const worksheet =  workbook.addWorksheet('My Sheet', {pageSetup:{paperSize: 9, orientation:'landscape'}
});// 創建一個具有頁眉頁腳的工作表
const sheet = workbook.addWorksheet('My Sheet', {headerFooter:{firstHeader: "Hello Exceljs", firstFooter: "Hello World"}
});// 創建一個凍結了第一行和第一列的工作表
const sheet = workbook.addWorksheet('My Sheet', {views:[{state: 'frozen', xSplit: 1, ySplit:1}]});

刪除工作表?

使用工作表的 id 從工作簿中刪除工作表。

示例:

// 創建工作表
const sheet = workbook.addWorksheet('My Sheet');// 使用工作表 id 刪除工作表
workbook.removeWorksheet(sheet.id)

訪問工作表?

// 遍歷所有工作表
// 注意: workbook.worksheets.forEach 仍然是可以正常運行的, 但是以下的方式更好
workbook.eachSheet(function(worksheet, sheetId) {// ...
});// 按 name 提取工作表
const worksheet = workbook.getWorksheet('My Sheet');// 按 id 提取工作表
const worksheet = workbook.getWorksheet(1);

工作表狀態?

// 使工作表可見
worksheet.state = 'visible';// 隱藏工作表
worksheet.state = 'hidden';// 從“隱藏/取消隱藏”對話框中隱藏工作表
worksheet.state = 'veryHidden';

工作表屬性?

工作表支持屬性存儲,以允許控制工作表的某些功能。

// 創建具有屬性的新工作表
const worksheet = workbook.addWorksheet('sheet', {properties:{tabColor:{argb:'FF00FF00'}}});// 創建一個具有屬性的可寫的新工作表
const worksheetWriter = workbookWriter.addWorksheet('sheet', {properties:{outlineLevelCol:1}});// 之后調整屬性(工作表讀寫器不支持該操作)
worksheet.properties.outlineLevelCol = 2;
worksheet.properties.defaultRowHeight = 15;

支持的屬性

屬性名默認值描述
tabColorundefined標簽的顏色
outlineLevelCol0工作表列大綱級別
outlineLevelRow0工作表行大綱級別
defaultRowHeight15默認行高
defaultColWidth(optional)默認列寬
dyDescent55TBD

工作表尺寸?

一些新的尺寸屬性已添加到工作表中…

屬性名描述
rowCount文檔的總行數。 等于具有值的最后一行的行號。
actualRowCount具有值的行數的計數。 如果中間文檔行為空,則該行將不包括在計數中。
columnCount文檔的總列數。 等于所有行的最大單元數。
actualColumnCount具有值的列數的計數。

頁面設置?

所有可能影響工作表打印的屬性都保存在工作表上的 pageSetup 對象中。

// 使用 A4 橫向的頁面設置創建新工作表
const worksheet =  workbook.addWorksheet('sheet', {pageSetup:{paperSize: 9, orientation:'landscape'}
});// 使用適合頁面的pageSetup設置創建一個新的工作表編寫器
const worksheetWriter = workbookWriter.addWorksheet('sheet', {pageSetup:{fitToPage: true, fitToHeight: 5, fitToWidth: 7}
});// 之后調整頁面設置配置
worksheet.pageSetup.margins = {left: 0.7, right: 0.7,top: 0.75, bottom: 0.75,header: 0.3, footer: 0.3
};// 設置工作表的打印區域
worksheet.pageSetup.printArea = 'A1:G20';// 通過使用 `&&` 分隔打印區域來設置多個打印區域
worksheet.pageSetup.printArea = 'A1:G10&&A11:G20';// 在每個打印頁面上重復特定的行
worksheet.pageSetup.printTitlesRow = '1:3';// 在每個打印頁面上重復特定列
worksheet.pageSetup.printTitlesColumn = 'A:C';

支持的頁面設置配置項

屬性名默認值描述
margins頁面上的空白邊距。 單位為英寸。
orientation'portrait'頁面方向 - 即較高 ('portrait') 或者較寬 ('landscape')
horizontalDpi4294967295水平方向上的 DPI。默認值為 -1
verticalDpi4294967295垂直方向上的 DPI。默認值為 -1
fitToPage是否使用 fitToWidthfitToHeightscale 設置。默認基于存在于 pageSetup 對象中的設置-如果兩者都存在,則 scale 優先級高(默認值為 false)。
pageOrder'downThenOver'打印頁面的順序-['downThenOver', 'overThenDown'] 之一
blackAndWhitefalse無色打印
draftfalse打印質量較低(墨水)
cellComments'None'在何處放置批注-['atEnd','asDisplayed','None']中的一個
errors'displayed'哪里顯示錯誤 -['dash', 'blank', 'NA', 'displayed'] 之一
scale100增加或減小打印尺寸的百分比值。 當 fitToPagefalse 時激活
fitToWidth1紙張應打印多少頁寬。 當 fitToPagetrue 時激活
fitToHeight1紙張應打印多少頁高。 當 fitToPagetrue 時激活
paperSize使用哪種紙張尺寸(見下文)
showRowColHeadersfalse是否顯示行號和列字母
showGridLinesfalse是否顯示網格線
firstPageNumber第一頁使用哪個頁碼
horizontalCenteredfalse是否將工作表數據水平居中
verticalCenteredfalse是否將工作表數據垂直居中

示例紙張尺寸

屬性名
Letterundefined
Legal5
Executive7
A38
A49
A511
B5 (JIS)13
Envelope #1020
Envelope DL27
Envelope C528
Envelope B534
Envelope Monarch37
Double Japan Postcard Rotated82
16K 197x273 mm119

頁眉和頁腳?

這是添加頁眉和頁腳的方法。
添加的內容主要是文本,例如時間,簡介,文件信息等,您可以設置文本的樣式。
此外,您可以為首頁和偶數頁設置不同的文本。

注意:目前不支持圖片。

// 創建一個帶有頁眉和頁腳的工作表
var sheet = workbook.addWorksheet('My Sheet', {headerFooter:{firstHeader: "Hello Exceljs", firstFooter: "Hello World"}
});// 創建一個帶有頁眉和頁腳可寫的工作表
var worksheetWriter = workbookWriter.addWorksheet('sheet', {headerFooter:{firstHeader: "Hello Exceljs", firstFooter: "Hello World"}
});
// 代碼中出現的&開頭字符對應變量,相關信息可查閱下文的變量表
// 設置頁腳(默認居中),結果:“第 2 頁,共 16 頁”
worksheet.headerFooter.oddFooter = "第 &P 頁,共 &N 頁";// 將頁腳(默認居中)設置為粗體,結果是:“第2頁,共16頁”
worksheet.headerFooter.oddFooter = "Page &P of &N";// 將左頁腳設置為 18px 并以斜體顯示。 結果:“第2頁,共16頁”
worksheet.headerFooter.oddFooter = "&LPage &P of &N";// 將中間標題設置為灰色Aril,結果為:“ 52 exceljs”
worksheet.headerFooter.oddHeader = "&C&KCCCCCC&\"Aril\"52 exceljs";// 設置頁腳的左,中和右文本。 結果:頁腳左側為“ Exceljs”。 頁腳中心的“ demo.xlsx”。 頁腳右側的“第2頁”
worksheet.headerFooter.oddFooter = "&Lexceljs&C&F&RPage &P";// 在首頁添加不同的頁眉和頁腳
worksheet.headerFooter.differentFirst = true;
worksheet.headerFooter.firstHeader = "Hello Exceljs";
worksheet.headerFooter.firstFooter = "Hello World"

支持的 headerFooter 設置

屬性名默認值描述
differentFirstfalsedifferentFirst 的值設置為 true,這表示第一頁的頁眉/頁腳與其他頁不同
differentOddEvenfalsedifferentOddEven 的值設置為 true,表示奇數頁和偶數頁的頁眉/頁腳不同
oddHeadernull設置奇數(默認)頁面的標題字符串,可以設置格式化字符串
oddFooternull設置奇數(默認)頁面的頁腳字符串,可以設置格式化字符串
evenHeadernull設置偶數頁的標題字符串,可以設置格式化字符串
evenFooternull為偶數頁設置頁腳字符串,可以設置格式化字符串
firstHeadernull設置首頁的標題字符串,可以設置格式化字符串
firstFooternull設置首頁的頁腳字符串,可以設置格式化字符串

腳本命令

命令描述
&L將位置設定在左側
&C將位置設置在中心
&R將位置設定在右邊
&P當前頁碼
&N總頁數
&D當前日期
&T當前時間
&G照片
&A工作表名稱
&F文件名稱
&B加粗文本
&I斜體文本
&U文本下劃線
&“font name”字體名稱,例如&“ Aril”
&font size字體大小,例如12
&KHEXCode字體顏色,例如 &KCCCCCC

工作表視圖?

現在,工作表支持視圖列表,這些視圖控制Excel如何顯示工作表:

  • frozen - 頂部和左側的許多行和列被凍結在適當的位置。 僅右下部分會滾動
  • split - 該視圖分為4個部分,每個部分可半獨立滾動。

每個視圖還支持各種屬性:

屬性名默認值描述
state'normal'控制視圖狀態 - 'normal', 'frozen' 或者 'split' 之一
rightToLeftfalse將工作表視圖的方向設置為從右到左
activeCellundefined當前選擇的單元格
showRulertrue在頁面布局中顯示或隱藏標尺
showRowColHeaderstrue顯示或隱藏行標題和列標題(例如,頂部的 A1,B1 和左側的1,2,3)
showGridLinestrue顯示或隱藏網格線(針對未定義邊框的單元格顯示)
zoomScale100用于視圖的縮放比例
zoomScaleNormal100正常縮放視圖
styleundefined演示樣式- pageBreakPreviewpageLayout 之一。 注意:頁面布局與 frozen 視圖不兼容

凍結視圖?

凍結視圖支持以下額外屬性:

屬性名默認值描述
xSplit0凍結多少列。要僅凍結行,請將其設置為 0undefined
ySplit0凍結多少行。要僅凍結列,請將其設置為 0undefined
topLeftCellspecial哪個單元格將在右下窗格中的左上角。注意:不能是凍結單元格。默認為第一個未凍結的單元格
worksheet.views = [{state: 'frozen', xSplit: 2, ySplit: 3, topLeftCell: 'G10', activeCell: 'A1'}
];

拆分視圖?

拆分視圖支持以下額外屬性:

屬性名默認值描述
xSplit0從左側多少個點起,以放置拆分器。要垂直拆分,請將其設置為 0undefined
ySplit0從頂部多少個點起,放置拆分器。要水平拆分,請將其設置為 0undefined
topLeftCellundefined哪個單元格將在右下窗格中的左上角。
activePaneundefined哪個窗格將處于活動狀態-topLefttopRightbottomLeftbottomRight 中的一個
worksheet.views = [{state: 'split', xSplit: 2000, ySplit: 3000, topLeftCell: 'G10', activeCell: 'A1'}
];

自動篩選器?

可以對工作表應用自動篩選器。

worksheet.autoFilter = 'A1:C1';

盡管范圍字符串是 autoFilter 的標準形式,但工作表還將支持以下值:

// 將自動篩選器設置為從 A1 到 C1
worksheet.autoFilter = {from: 'A1',to: 'C1',
}// 將自動篩選器設置為從第3行第1列的單元格到第5行第12列的單元格
worksheet.autoFilter = {from: {row: 3,column: 1},to: {row: 5,column: 12}
}// 將自動篩選器設置為從D3到第7行第5列中的單元格
worksheet.autoFilter = {from: 'D3',to: {row: 7,column: 5}
}

?

// 添加列標題并定義列鍵和寬度
// 注意:這些列結構僅是構建工作簿的方便之處,除了列寬之外,它們不會完全保留。
worksheet.columns = [{ header: 'Id', key: 'id', width: 10 },{ header: 'Name', key: 'name', width: 32 },{ header: 'D.O.B.', key: 'DOB', width: 10, outlineLevel: 1 }
];// 通過鍵,字母和基于1的列號訪問單個列
const idCol = worksheet.getColumn('id');
const nameCol = worksheet.getColumn('B');
const dobCol = worksheet.getColumn(3);// 設置列屬性// 注意:將覆蓋 C1 單元格值
dobCol.header = 'Date of Birth';// 注意:這將覆蓋 C1:C2 單元格值
dobCol.header = ['Date of Birth', 'A.K.A. D.O.B.'];// 從現在開始,此列將以 “dob” 而不是 “DOB” 建立索引
dobCol.key = 'dob';dobCol.width = 15;// 如果需要,隱藏列
dobCol.hidden = true;// 為列設置大綱級別
worksheet.getColumn(4).outlineLevel = 0;
worksheet.getColumn(5).outlineLevel = 1;// 列支持一個只讀字段,以指示基于 `OutlineLevel` 的折疊狀態
expect(worksheet.getColumn(4).collapsed).to.equal(false);
expect(worksheet.getColumn(5).collapsed).to.equal(true);// 遍歷此列中的所有當前單元格
dobCol.eachCell(function(cell, rowNumber) {// ...
});// 遍歷此列中的所有當前單元格,包括空單元格
dobCol.eachCell({ includeEmpty: true }, function(cell, rowNumber) {// ...
});// 添加一列新值
worksheet.getColumn(6).values = [1,2,3,4,5];// 添加稀疏列值
worksheet.getColumn(7).values = [,,2,3,,5,,7,,,,11];// 剪切一列或多列(右邊的列向左移動)
// 如果定義了列屬性,則會相應地對其進行切割或移動
// 已知問題:如果拼接導致任何合并的單元格移動,結果可能是不可預測的
worksheet.spliceColumns(3,2);// 刪除一列,再插入兩列。
// 注意:第4列及以上的列將右移1列。
// 另外:如果工作表中的行數多于列插入項中的值,則行將仍然被插入,就好像值存在一樣。
const newCol3Values = [1,2,3,4,5];
const newCol4Values = ['one', 'two', 'three', 'four', 'five'];
worksheet.spliceColumns(3, 1, newCol3Values, newCol4Values);

?

// 獲取一個行對象。如果尚不存在,則將返回一個新的空對象
const row = worksheet.getRow(5);// Get multiple row objects. If it doesn't already exist, new empty ones will be returned
const rows = worksheet.getRows(5, 2); // start, length (>0, else undefined is returned)// 獲取工作表中的最后一個可編輯行(如果沒有,則為 `undefined`)
const row = worksheet.lastRow;// 設置特定的行高
row.height = 42.5;// 隱藏行
row.hidden = true;// 為行設置大綱級別
worksheet.getRow(4).outlineLevel = 0;
worksheet.getRow(5).outlineLevel = 1;// 行支持一個只讀字段,以指示基于 `OutlineLevel` 的折疊狀態
expect(worksheet.getRow(4).collapsed).to.equal(false);
expect(worksheet.getRow(5).collapsed).to.equal(true);row.getCell(1).value = 5; // A5 的值設置為5
row.getCell('name').value = 'Zeb'; // B5 的值設置為 “Zeb” - 假設第2列仍按名稱鍵入
row.getCell('C').value = new Date(); // C5 的值設置為當前時間// 獲取行并作為稀疏數組返回
// 注意:接口更改:worksheet.getRow(4) ==> worksheet.getRow(4).values
row = worksheet.getRow(4).values;
expect(row[5]).toEqual('Kyle');// 通過連續數組分配行值(其中數組元素 0 具有值)
row.values = [1,2,3];
expect(row.getCell(1).value).toEqual(1);
expect(row.getCell(2).value).toEqual(2);
expect(row.getCell(3).value).toEqual(3);// 通過稀疏數組分配行值(其中數組元素 0 為 `undefined`)
const values = []
values[5] = 7;
values[10] = 'Hello, World!';
row.values = values;
expect(row.getCell(1).value).toBeNull();
expect(row.getCell(5).value).toEqual(7);
expect(row.getCell(10).value).toEqual('Hello, World!');// 使用列鍵按對象分配行值
row.values = {id: 13,name: 'Thing 1',dob: new Date()
};// 在該行下方插入一個分頁符
row.addPageBreak();// 遍歷工作表中具有值的所有行
worksheet.eachRow(function(row, rowNumber) {console.log('Row ' + rowNumber + ' = ' + JSON.stringify(row.values));
});// 遍歷工作表中的所有行(包括空行)
worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {console.log('Row ' + rowNumber + ' = ' + JSON.stringify(row.values));
});// 連續遍歷所有非空單元格
row.eachCell(function(cell, colNumber) {console.log('Cell ' + colNumber + ' = ' + cell.value);
});// 遍歷一行中的所有單元格(包括空單元格)
row.eachCell({ includeEmpty: true }, function(cell, colNumber) {console.log('Cell ' + colNumber + ' = ' + cell.value);
});// 提交給流一個完成的行
row.commit();// 行尺寸
const rowSize = row.cellCount;
const numValues = row.actualCellCount;

Add Rows?

// Add a couple of Rows by key-value, after the last current row, using the column keys
worksheet.addRow({id: 1, name: 'John Doe', dob: new Date(1970,1,1)});
worksheet.addRow({id: 2, name: 'Jane Doe', dob: new Date(1965,1,7)});// Add a row by contiguous Array (assign to columns A, B & C)
worksheet.addRow([3, 'Sam', new Date()]);// Add a row by sparse Array (assign to columns A, E & I)
const rowValues = [];
rowValues[1] = 4;
rowValues[5] = 'Kyle';
rowValues[9] = new Date();
worksheet.addRow(rowValues);// Add a row with inherited style
// This new row will have same style as last row
// And return as row object
const newRow = worksheet.addRow(rowValues, 'i');// Add an array of rows
const rows = [[5,'Bob',new Date()], // row by array{id:6, name: 'Barbara', dob: new Date()}
];
// add new rows and return them as array of row objects
const newRows = worksheet.addRows(rows);// Add an array of rows with inherited style
// These new rows will have same styles as last row
// and return them as array of row objects
const newRowsStyled = worksheet.addRows(rows, 'i');
ParameterDescriptionDefault Value
value/sThe new row/s values
style‘i’ for inherit from row above, ‘i+’ to include empty cells, ‘n’ for none‘n’

處理單個單元格?

const cell = worksheet.getCell('C3');// 修改/添加單個單元格
cell.value = new Date(1968, 5, 1);// 查詢單元格的類型
expect(cell.type).toEqual(Excel.ValueType.Date);// 使用單元格的字符串值
myInput.value = cell.text;// 使用 html 安全的字符串進行渲染...
const html = '<div>' + cell.html + '</div>';

合并單元格?

// 合并一系列單元格
worksheet.mergeCells('A4:B5');// ...合并的單元格被鏈接起來了
worksheet.getCell('B5').value = 'Hello, World!';
expect(worksheet.getCell('B5').value).toBe(worksheet.getCell('A4').value);
expect(worksheet.getCell('B5').master).toBe(worksheet.getCell('A4'));// ...合并的單元格共享相同的樣式對象
expect(worksheet.getCell('B5').style).toBe(worksheet.getCell('A4').style);
worksheet.getCell('B5').style.font = myFonts.arial;
expect(worksheet.getCell('A4').style.font).toBe(myFonts.arial);// 取消單元格合并將打破鏈接的樣式
worksheet.unMergeCells('A4');
expect(worksheet.getCell('B5').style).not.toBe(worksheet.getCell('A4').style);
expect(worksheet.getCell('B5').style.font).not.toBe(myFonts.arial);// 按左上,右下合并
worksheet.mergeCells('K10', 'M12');// 按開始行,開始列,結束行,結束列合并(相當于 K10:M12)
worksheet.mergeCells(10,11,12,13);

Insert Rows?

insertRow(pos, value, style = 'n')
insertRows(pos, values, style = 'n')// Insert a couple of Rows by key-value, shifting down rows every time
worksheet.insertRow(1, {id: 1, name: 'John Doe', dob: new Date(1970,1,1)});
worksheet.insertRow(1, {id: 2, name: 'Jane Doe', dob: new Date(1965,1,7)});// Insert a row by contiguous Array (assign to columns A, B & C)
worksheet.insertRow(1, [3, 'Sam', new Date()]);// Insert a row by sparse Array (assign to columns A, E & I)
var rowValues = [];
rowValues[1] = 4;
rowValues[5] = 'Kyle';
rowValues[9] = new Date();
// insert new row and return as row object
const insertedRow = worksheet.insertRow(1, rowValues);// Insert a row, with inherited style
// This new row will have same style as row on top of it
// And return as row object
const insertedRowInherited = worksheet.insertRow(1, rowValues, 'i');// Insert a row, keeping original style
// This new row will have same style as it was previously
// And return as row object
const insertedRowOriginal = worksheet.insertRow(1, rowValues, 'o');// Insert an array of rows, in position 1, shifting down current position 1 and later rows by 2 rows
var rows = [[5,'Bob',new Date()], // row by array{id:6, name: 'Barbara', dob: new Date()}
];
// insert new rows and return them as array of row objects
const insertedRows = worksheet.insertRows(1, rows);// Insert an array of rows, with inherited style
// These new rows will have same style as row on top of it
// And return them as array of row objects
const insertedRowsInherited = worksheet.insertRows(1, rows, 'i');// Insert an array of rows, keeping original style
// These new rows will have same style as it was previously in 'pos' position
const insertedRowsOriginal = worksheet.insertRows(1, rows, 'o');
ParameterDescriptionDefault Value
posRow number where you want to insert, pushing down all rows from there
value/sThe new row/s values
style‘i’ for inherit from row above, , ‘i+’ to include empty cells, ‘o’ for original style, ‘o+’ to include empty cells, ‘n’ for none‘n’

Splice?

// Cut one or more rows (rows below are shifted up)
// Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
worksheet.spliceRows(4, 3);// remove one row and insert two more.
// Note: rows 4 and below will be shifted down by 1 row.
const newRow3Values = [1, 2, 3, 4, 5];
const newRow4Values = ['one', 'two', 'three', 'four', 'five'];
worksheet.spliceRows(3, 1, newRow3Values, newRow4Values);// Cut one or more cells (cells to the right are shifted left)
// Note: this operation will not affect other rows
row.splice(3, 2);// remove one cell and insert two more (cells to the right of the cut cell will be shifted right)
row.splice(4, 1, 'new value 1', 'new value 2');
ParameterDescriptionDefault Value
startStarting point to splice from
countNumber of rows/cells to remove
…insertsNew row/cell values to insert

重復行?

duplicateRow(start, amount = 1, insert = true)const wb = new ExcelJS.Workbook();
const ws = wb.addWorksheet('duplicateTest');
ws.getCell('A1').value = 'One';
ws.getCell('A2').value = 'Two';
ws.getCell('A3').value = 'Three';
ws.getCell('A4').value = 'Four';// 該行將重復復制第一行兩次,但將替換第二行和第三行
// 如果第三個參數為 true,則它將插入2個新行,其中包含行 “One” 的值和樣式
ws.duplicateRow(1,2,false);
參數描述默認值
start要復制的行號(Excel中的第一個是1)
amount您要復制行的次數1
insert如果要為重復項插入新行,則為 true,否則為 false 將替換已有行true

定義名稱?

單個單元格(或多個單元格組)可以為它們分配名稱。名稱可用于公式和數據驗證(可能還有更多)。

// 為單元格分配(或獲取)名稱(將覆蓋該單元具有的其他任何名稱)
worksheet.getCell('A1').name = 'PI';
expect(worksheet.getCell('A1').name).to.equal('PI');// 為單元格分配(或獲取)一組名稱(單元可以具有多個名稱)
worksheet.getCell('A1').names = ['thing1', 'thing2'];
expect(worksheet.getCell('A1').names).to.have.members(['thing1', 'thing2']);// 從單元格中刪除名稱
worksheet.getCell('A1').removeName('thing1');
expect(worksheet.getCell('A1').names).to.have.members(['thing2']);

數據驗證?

單元格可以定義哪些值有效或無效,并提示用戶以幫助指導它們。

驗證類型可以是以下之一:

類型描述
list定義一組離散的有效值。Excel 將在下拉菜單中提供這些內容,以便于輸入
whole該值必須是整數
decimal該值必須是十進制數
textLength該值可以是文本,但長度是受控的
custom自定義公式控制有效值

對于 listcustom 以外的其他類型,以下運算符會影響驗證:

運算符描述
between值必須介于公式結果之間
notBetween值不能介于公式結果之間
equal值必須等于公式結果
notEqual值不能等于公式結果
greaterThan值必須大于公式結果
lessThan值必須小于公式結果
greaterThanOrEqual值必須大于或等于公式結果
lessThanOrEqual值必須小于或等于公式結果
// 指定有效值的列表(One,Two,Three,Four)。
// Excel 將提供一個包含這些值的下拉列表。
worksheet.getCell('A1').dataValidation = {type: 'list',allowBlank: true,formulae: ['"One,Two,Three,Four"']
};// 指定范圍內的有效值列表。
// Excel 將提供一個包含這些值的下拉列表。
worksheet.getCell('A1').dataValidation = {type: 'list',allowBlank: true,formulae: ['$D$5:$F$5']
};// 指定單元格必須為非5的整數。
// 向用戶顯示適當的錯誤消息(如果他們弄錯了)
worksheet.getCell('A1').dataValidation = {type: 'whole',operator: 'notEqual',showErrorMessage: true,formulae: [5],errorStyle: 'error',errorTitle: 'Five',error: 'The value must not be Five'
};// 指定單元格必須為1.5到7之間的十進制數字。
// 添加“工具提示”以幫助指導用戶
worksheet.getCell('A1').dataValidation = {type: 'decimal',operator: 'between',allowBlank: true,showInputMessage: true,formulae: [1.5, 7],promptTitle: 'Decimal',prompt: 'The value must between 1.5 and 7'
};// 指定單元格的文本長度必須小于15
worksheet.getCell('A1').dataValidation = {type: 'textLength',operator: 'lessThan',showErrorMessage: true,allowBlank: true,formulae: [15]
};// 指定單元格必須是2016年1月1日之前的日期
worksheet.getCell('A1').dataValidation = {type: 'date',operator: 'lessThan',showErrorMessage: true,allowBlank: true,formulae: [new Date(2016,0,1)]
};

單元格注釋?

將舊樣式的注釋添加到單元格

// 純文字筆記
worksheet.getCell('A1').note = 'Hello, ExcelJS!';// 彩色格式化的筆記
ws.getCell('B1').note = {texts: [{'font': {'size': 12, 'color': {'theme': 0}, 'name': 'Calibri', 'family': 2, 'scheme': 'minor'}, 'text': 'This is '},{'font': {'italic': true, 'size': 12, 'color': {'theme': 0}, 'name': 'Calibri', 'scheme': 'minor'}, 'text': 'a'},{'font': {'size': 12, 'color': {'theme': 1}, 'name': 'Calibri', 'family': 2, 'scheme': 'minor'}, 'text': ' '},{'font': {'size': 12, 'color': {'argb': 'FFFF6600'}, 'name': 'Calibri', 'scheme': 'minor'}, 'text': 'colorful'},{'font': {'size': 12, 'color': {'theme': 1}, 'name': 'Calibri', 'family': 2, 'scheme': 'minor'}, 'text': ' text '},{'font': {'size': 12, 'color': {'argb': 'FFCCFFCC'}, 'name': 'Calibri', 'scheme': 'minor'}, 'text': 'with'},{'font': {'size': 12, 'color': {'theme': 1}, 'name': 'Calibri', 'family': 2, 'scheme': 'minor'}, 'text': ' in-cell '},{'font': {'bold': true, 'size': 12, 'color': {'theme': 1}, 'name': 'Calibri', 'family': 2, 'scheme': 'minor'}, 'text': 'format'},],margins: {insetmode: 'custom',inset: [0.25, 0.25, 0.35, 0.35]},protection: {locked: True,lockText: False},editAs: 'twoCells'
};

單元格批注屬性?

下表定義了單元格注釋已支持的屬性。

FieldRequiredDefault ValueDescription
textsY評論文字
marginsN{}確定自動或自定義設置單元格注釋的邊距值
protectionN{}可以使用保護屬性來指定對象和對象文本的鎖定狀態
editAsN‘absolute’可以使用’editAs’屬性來指定注釋如何錨定到單元格

單元格批注頁邊距?

確定單元格批注的頁面距設置模式,自動或者自定義模式。

ws.getCell('B1').note.margins = {insetmode: 'custom',inset: [0.25, 0.25, 0.35, 0.35]
}

已支持的頁邊距屬性?

PropertyRequiredDefault ValueDescription
insetmodeN‘auto’確定是否自動設置注釋邊距,并且值是’auto’ 或者 ‘custom’
insetN[0.13, 0.13, 0.25, 0.25]批注頁邊距的值,單位是厘米, 方向是左-上-右-下

注意:只有當 insetmode的值設置為’custom’時,inset的設置才生效。

單元格批注保護?

可以使用保護屬性來修改單元級別保護。

ws.getCell('B1').note.protection = {locked: 'False',lockText: 'False',
};

已支持的保護屬性?

PropertyRequiredDefault ValueDescription
lockedN‘True’此元素指定在保護工作表時對象已鎖定
lockTextN‘True’該元素指定對象的文本已鎖定

單元格批注對象位置屬性?

單元格注釋還可以具有屬性 ‘editAs’,該屬性將控制注釋如何錨定到單元格。
它可以具有以下值之一:

ws.getCell('B1').note.editAs = 'twoCells'
ValueDescription
twoCells它指定注釋的大小、位置隨單元格而變
oneCells它指定注釋的大小固定,位置隨單元格而變
absolute這是默認值,它指定注釋的大小、位置均固定

表格?

表允許表格內數據的表內操作。

要將表添加到工作表,請定義表模型并調用 addTable

// 將表格添加到工作表
ws.addTable({name: 'MyTable',ref: 'A1',headerRow: true,totalsRow: true,style: {theme: 'TableStyleDark3',showRowStripes: true,},columns: [{name: 'Date', totalsRowLabel: 'Totals:', filterButton: true},{name: 'Amount', totalsRowFunction: 'sum', filterButton: false},],rows: [[new Date('2019-07-20'), 70.10],[new Date('2019-07-21'), 70.60],[new Date('2019-07-22'), 70.10],],
});

注意:將表格添加到工作表將通過放置表格的標題和行數據來修改工作表。
結果就是表格覆蓋的工作表上的所有數據(包括標題和所有的)都將被覆蓋。

表格屬性?

下表定義了表格支持的屬性。

表屬性描述是否需要默認值
name表格名稱Y
displayName表格的顯示名稱Nname
ref表格的左上方單元格Y
headerRow在表格頂部顯示標題Ntrue
totalsRow在表格底部顯示總計Nfalse
style額外的樣式屬性N{}
columns列定義Y
rows數據行Y

表格樣式屬性?

下表定義了表格中支持的屬性樣式屬性。

樣式屬性描述是否需要默認值
theme桌子的顏色主題N'TableStyleMedium2'
showFirstColumn突出顯示第一列(粗體)Nfalse
showLastColumn突出顯示最后一列(粗體)Nfalse
showRowStripes用交替的背景色顯示行Nfalse
showColumnStripes用交替的背景色顯示列Nfalse

表格列屬性?

下表定義了每個表格列中支持的屬性。

列屬性描述是否需要默認值
name列名,也用在標題中Y
filterButton切換標題中的過濾器控件Nfalse
totalsRowLabel用于描述統計行的標簽(第一列)N'Total'
totalsRowFunction統計函數名稱N'none'
totalsRowFormula自定義函數的可選公式N

統計函數?

下表列出了由列定義的 totalsRowFunction 屬性的有效值。如果使用 'custom' 以外的任何值,則無需包括關聯的公式,因為該公式將被表格插入。

統計函數描述
none此列沒有統計函數
average計算列的平均值
countNums統計數字條目數
count條目數
max此列中的最大值
min此列中的最小值
stdDev該列的標準偏差
var此列的方差
sum此列的條目總數
custom自定義公式。 需要關聯的 totalsRowFormula 值。

表格樣式主題?

有效的主題名稱遵循以下模式:

  • “TableStyle[Shade][Number]”

Shades(陰影),Number(數字)可以是以下之一:

  • Light, 1-21
  • Medium, 1-28
  • Dark, 1-11

對于無主題,請使用值 null

注意:exceljs 尚不支持自定義表格主題。

修改表格?

表格支持一組操作函數,這些操作函數允許添加或刪除數據以及更改某些屬性。由于這些操作中的許多操作可能會對工作表產生副作用,因此更改必須在完成后立即提交。

表中的所有索引值均基于零,因此第一行號和第一列號為 0

添加或刪除標題和統計

const table = ws.getTable('MyTable');// 打開標題行
table.headerRow = true;// 關閉統計行
table.totalsRow = false;// 將表更改提交到工作表中
table.commit();

重定位表

const table = ws.getTable('MyTable');// 表格左上移至 D4
table.ref = 'D4';// 將表更改提交到工作表中
table.commit();

添加和刪除行

const table = ws.getTable('MyTable');// 刪除前兩行
table.removeRows(0, 2);// 在索引 5 處插入新行
table.addRow([new Date('2019-08-05'), 5, 'Mid'], 5);// 在表格底部追加新行
table.addRow([new Date('2019-08-10'), 10, 'End']);// 將表更改提交到工作表中
table.commit();

添加和刪除列

const table = ws.getTable('MyTable');// 刪除第二列
table.removeColumns(1, 1);// 在索引 1 處插入新列(包含數據)
table.addColumn({name: 'Letter', totalsRowFunction: 'custom', totalsRowFormula: 'ROW()', totalsRowResult: 6, filterButton: true},['a', 'b', 'c', 'd'],2
);// 將表更改提交到工作表中
table.commit();

更改列屬性

const table = ws.getTable('MyTable');// 獲取第二列的列包裝器
const column = table.getColumn(1);// 設置一些屬性
column.name = 'Code';
column.filterButton = true;
column.style = {font:{bold: true, name: 'Comic Sans MS'}};
column.totalsRowLabel = 'Totals';
column.totalsRowFunction = 'custom';
column.totalsRowFormula = 'ROW()';
column.totalsRowResult = 10;// 將表更改提交到工作表中
table.commit();

樣式?

單元格,行和列均支持一組豐富的樣式和格式,這些樣式和格式會影響單元格的顯示方式。

通過分配以下屬性來設置樣式:

  • numFmt
  • font
  • alignment
  • border
  • fill
// 為單元格分配樣式
ws.getCell('A1').numFmt = '0.00%';// 將樣式應用于工作表列
ws.columns = [{ header: 'Id', key: 'id', width: 10 },{ header: 'Name', key: 'name', width: 32, style: { font: { name: 'Arial Black' } } },{ header: 'D.O.B.', key: 'DOB', width: 10, style: { numFmt: 'dd/mm/yyyy' } }
];// 將第3列設置為“貨幣格式”
ws.getColumn(3).numFmt = '"£"#,##0.00;[Red]\-"£"#,##0.00';// 將第2行設置為 Comic Sans。
ws.getRow(2).font = { name: 'Comic Sans MS', family: 4, size: 16, underline: 'double', bold: true };

將樣式應用于行或列時,它將應用于該行或列中所有當前存在的單元格。另外,創建的任何新單元格都將從其所屬的行和列繼承其初始樣式。

如果單元格的行和列都定義了特定的樣式(例如,字體),則該單元格所在行樣式比列樣式具有更高優先級。但是,如果行和列定義了不同的樣式(例如 column.numFmtrow.font),則單元格將繼承行的字體和列的 numFmt

注意:以上所有屬性(numFmt(字符串)除外)都是 JS 對象結構。如果將同一樣式對象分配給多個電子表格實體,則每個實體將共享同一樣式對象。如果樣式對象后來在電子表格序列化之前被修改,則所有引用該樣式對象的實體也將被修改。此行為旨在通過減少創建的JS對象的數量來優先考慮性能。如果希望樣式對象是獨立的,則需要先對其進行克隆,然后再分配它們。同樣,默認情況下,如果電子表格實體共享相似的樣式,則從文件(或流)中讀取文檔時,它們也將引用相同的樣式對象。

數字格式?

// 將值顯示為“ 1 3/5”
ws.getCell('A1').value = 1.6;
ws.getCell('A1').numFmt = '# ?/?';// 顯示為“ 1.60%”
ws.getCell('B1').value = 0.016;
ws.getCell('B1').numFmt = '0.00%';

字體


// for the wannabe graphic designers out there
ws.getCell('A1').font = {name: 'Comic Sans MS',family: 4,size: 16,underline: true,bold: true
};// for the graduate graphic designers...
ws.getCell('A2').font = {name: 'Arial Black',color: { argb: 'FF00FF00' },family: 2,size: 14,italic: true
};// 垂直對齊
ws.getCell('A3').font = {vertAlign: 'superscript'
};// 注意:該單元格將存儲對分配的字體對象的引用。
// 如果之后更改了字體對象,則單元字體也將更改。
const font = { name: 'Arial', size: 12 };
ws.getCell('A3').font = font;
font.size = 20; // 單元格 A3 現在具有20號字體!// 從文件或流中讀取工作簿后,共享相似字體的單元格可能引用相同的字體對象
字體屬性描述示例值
name字體名稱。‘Arial’, ‘Calibri’, etc.
family備用字體家族。整數值。1 - Serif, 2 - Sans Serif, 3 - Mono, Others - unknown
scheme字體方案。‘minor’, ‘major’, ‘none’
charset字體字符集。整數值。1, 2, etc.
size字體大小。整數值。9, 10, 12, 16, etc.
color顏色描述,一個包含 ARGB 值的對象。{ argb: ‘FFFF0000’}
bold字體 粗細true, false
italic字體 傾斜true, false
underline字體 下劃線 樣式true, false, ‘none’, ‘single’, ‘double’, ‘singleAccounting’, ‘doubleAccounting’
strike字體 刪除線 true, false
outline字體輪廓true, false
vertAlign垂直對齊‘superscript’, ‘subscript’

對齊?

// 將單元格對齊方式設置為左上,中間居中,右下
ws.getCell('A1').alignment = { vertical: 'top', horizontal: 'left' };
ws.getCell('B1').alignment = { vertical: 'middle', horizontal: 'center' };
ws.getCell('C1').alignment = { vertical: 'bottom', horizontal: 'right' };// 將單元格設置為自動換行
ws.getCell('D1').alignment = { wrapText: true };// 將單元格縮進設置為1
ws.getCell('E1').alignment = { indent: 1 };// 將單元格文本旋轉設置為向上30deg,向下45deg和垂直文本
ws.getCell('F1').alignment = { textRotation: 30 };
ws.getCell('G1').alignment = { textRotation: -45 };
ws.getCell('H1').alignment = { textRotation: 'vertical' };

有效的對齊屬性值

水平的垂直文本換行自適應縮進閱讀順序文本旋轉
lefttoptruetrueintegerrtl0 to 90
centermiddlefalsefalseltr-1 to -90
rightbottomvertical
filldistributed
justifyjustify
centerContinuous
distributed

邊框?

// 在A1周圍設置單個細邊框
ws.getCell('A1').border = {top: {style:'thin'},left: {style:'thin'},bottom: {style:'thin'},right: {style:'thin'}
};// 在A3周圍設置雙細綠色邊框
ws.getCell('A3').border = {top: {style:'double', color: {argb:'FF00FF00'}},left: {style:'double', color: {argb:'FF00FF00'}},bottom: {style:'double', color: {argb:'FF00FF00'}},right: {style:'double', color: {argb:'FF00FF00'}}
};// 在A5中設置厚紅十字邊框
ws.getCell('A5').border = {diagonal: {up: true, down: true, style:'thick', color: {argb:'FFFF0000'}}
};

有效邊框樣式

  • thin
  • dotted
  • dashDot
  • hair
  • dashDotDot
  • slantDashDot
  • mediumDashed
  • mediumDashDotDot
  • mediumDashDot
  • medium
  • double
  • thick

填充?

// 用紅色深色垂直條紋填充A1
ws.getCell('A1').fill = {type: 'pattern',pattern:'darkVertical',fgColor:{argb:'FFFF0000'}
};// 在A2中填充深黃色格子和藍色背景
ws.getCell('A2').fill = {type: 'pattern',pattern:'darkTrellis',fgColor:{argb:'FFFFFF00'},bgColor:{argb:'FF0000FF'}
};// 從左到右用藍白藍漸變填充A3
ws.getCell('A3').fill = {type: 'gradient',gradient: 'angle',degree: 0,stops: [{position:0, color:{argb:'FF0000FF'}},{position:0.5, color:{argb:'FFFFFFFF'}},{position:1, color:{argb:'FF0000FF'}}]
};// 從中心開始用紅綠色漸變填充A4
ws.getCell('A4').fill = {type: 'gradient',gradient: 'path',center:{left:0.5,top:0.5},stops: [{position:0, color:{argb:'FFFF0000'}},{position:1, color:{argb:'FF00FF00'}}]
};
填充模式?
屬性是否需要描述
typeY值: 'pattern'
指定此填充使用模式
patternY指定模式類型 (查看下面 有效模式類型 )
fgColorN指定圖案前景色。默認為黑色。
bgColorN指定圖案背景色。默認為白色。

有效模式類型

  • none
  • solid
  • darkGray
  • mediumGray
  • lightGray
  • gray125
  • gray0625
  • darkHorizontal
  • darkVertical
  • darkDown
  • darkUp
  • darkGrid
  • darkTrellis
  • lightHorizontal
  • lightVertical
  • lightDown
  • lightUp
  • lightGrid
  • lightTrellis
漸變填充?
屬性是否需要描述
typeY值: 'gradient'
指定此填充使用漸變
gradientY指定漸變類型。['angle','path'] 之一
degreeangle對于“角度”漸變,指定漸變的方向。0 是從左到右。值從 1-359 順時針旋轉方向
centerpath對于“路徑”漸變。指定路徑起點的相對坐標。“左”和“頂”值的范圍是 0 到 1
stopsY指定漸變顏色序列。是包含位置和顏色(從位置 0 開始到位置 1 結束)的對象的數組。中間位置可用于指定路徑上的其他顏色。

注意事項

使用上面的接口,可能會創建使用XLSX編輯器程序無法實現的漸變填充效果。例如,Excel 僅支持0、45、90 和 135 的角度梯度。類似地,stops 的順序也可能受到 UI 的限制,其中位置 [0,1] 或[0,0.5,1] 是唯一的選擇。請謹慎處理此填充,以確保目標 XLSX 查看器支持該填充。

富文本?

現在,單個單元格支持RTF文本或單元格格式化。富文本值可以控制文本值內任意數量的子字符串的字體屬性。有關支持哪些字體屬性的詳細信息,請參見字體。


ws.getCell('A1').value = {'richText': [{'font': {'size': 12,'color': {'theme': 0},'name': 'Calibri','family': 2,'scheme': 'minor'},'text': 'This is '},{'font': {'italic': true,'size': 12,'color': {'theme': 0},'name': 'Calibri','scheme': 'minor'},'text': 'a'},{'font': {'size': 12,'color': {'theme': 1},'name': 'Calibri','family': 2,'scheme': 'minor'},'text': ' '},{'font': {'size': 12,'color': {'argb': 'FFFF6600'},'name': 'Calibri','scheme': 'minor'},'text': 'colorful'},{'font': {'size': 12,'color': {'theme': 1},'name': 'Calibri','family': 2,'scheme': 'minor'},'text': ' text '},{'font': {'size': 12,'color': {'argb': 'FFCCFFCC'},'name': 'Calibri','scheme': 'minor'},'text': 'with'},{'font': {'size': 12,'color': {'theme': 1},'name': 'Calibri','family': 2,'scheme': 'minor'},'text': ' in-cell '},{'font': {'bold': true,'size': 12,'color': {'theme': 1},'name': 'Calibri','family': 2,'scheme': 'minor'},'text': 'format'}]
};expect(ws.getCell('A1').text).to.equal('This is a colorful text with in-cell format');
expect(ws.getCell('A1').type).to.equal(Excel.ValueType.RichText);

單元格保護?

可以使用保護屬性來修改單元級別保護。

ws.getCell('A1').protection = {locked: false,hidden: true,
};

支持的保護屬性

屬性默認值描述
lockedtrue指定在工作表受保護的情況下是否將單元格鎖定。
hiddenfalse指定如果工作表受保護,則單元格的公式是否可見。

條件格式化?

條件格式化允許工作表根據單元格值或任意公式顯示特定的樣式,圖標等。

條件格式設置規則是在工作表級別添加的,通常會覆蓋一系列單元格。

可以將多個規則應用于給定的單元格范圍,并且每個規則都將應用自己的樣式。

如果多個規則影響給定的單元格,則規則優先級值將確定如果競爭樣式沖突,則哪個規則勝出。優先級值較低的規則獲勝。如果沒有為給定規則指定優先級值,ExcelJS 將按升序分配它們。

注意:目前,僅支持條件格式設置規則的子集。具體來說,只有格式規則不需要 <extLst&gt 元素內的 XML 呈現。這意味著不支持數據集和三個特定的圖標集(3Triangles,3Stars,5Boxes)。

// 根據行和列為偶數或奇數向 A1:E7 添加一個棋盤圖案
worksheet.addConditionalFormatting({ref: 'A1:E7',rules: [{type: 'expression',formulae: ['MOD(ROW()+COLUMN(),2)=0'],style: {fill: {type: 'pattern', pattern: 'solid', bgColor: {argb: 'FF00FF00'}}},}]
})

支持的條件格式設置規則類型

類型描述
expression任何自定義功能均可用于激活規則。
cellIs使用指定的運算符將單元格值與提供的公式進行比較
top10將格式化應用于值在頂部(或底部)范圍內的單元格
aboveAverage將格式化應用于值高于(或低于)平均值的單元格
colorScale根據其值在范圍內的位置將彩色背景應用于單元格
iconSet根據值將一系列圖標之一添加到單元格
containsText根據單元格是否為特定文本來應用格式
timePeriod根據單元格日期時間值是否在指定范圍內應用格式

表達式?

屬性可選默認值描述
type'expression'
priorityY<auto>確定樣式的優先順序
formulae1個包含真/假值的公式字符串數組。要引用單元格值,請使用左上角的單元格地址
style公式返回 true 時要應用的樣式結構

Cell Is?

屬性可選默認值描述
type'cellIs'
priorityY<auto>確定樣式的優先順序
operator如何將單元格值與公式結果進行比較
formulae1個公式字符串數組,返回要與每個單元格進行比較的值
style如果比較返回 true,則應用樣式結構

Cell Is 運算符

運算描述
equal如果單元格值等于公式值,則應用格式
greaterThan如果單元格值大于公式值,則應用格式
lessThan如果單元格值小于公式值,則應用格式
between如果單元格值在兩個公式值之間(包括兩個值),則應用格式

Top 10?

屬性可選默認值描述
type'top10'
priorityY<auto>確定樣式的優先順序
rankY10指定格式中包含多少個頂部(或底部)值
percentYfalse如果為 true,則等級字段為百分比,而不是絕對值
bottomYfalse如果為 true,則包含最低值而不是最高值
style如果比較返回 true,則應用樣式結構

高于平均值?

屬性可選默認值描述
type'aboveAverage'
priorityY<auto>確定樣式的優先順序
aboveAverageYfalse如果為 true,則等級字段為百分比,而不是絕對值
style如果比較返回 true,則應用樣式結構

色階?

屬性可選默認值描述
type'colorScale'
priorityY<auto>確定樣式的優先順序
cfvo2到5個條件格式化值對象的數組,指定值范圍內的航路點
color在給定的航路點使用的相應顏色數組
style如果比較返回 true,則應用樣式結構

圖標集?

屬性可選默認值描述
type'iconSet'
priorityY<auto>確定樣式的優先順序
iconSetY3TrafficLights設置使用的圖標名稱
showValuetrue指定應用范圍內的單元格是顯示圖標和單元格值,還是僅顯示圖標
reversefalse指定是否以保留順序顯示 iconSet 中指定的圖標集中的圖標。 如果 custom 等于 true,則必須忽略此值
customfalse指定是否使用自定義圖標集
cfvo2到5個條件格式化值對象的數組,指定值范圍內的航路點
style如果比較返回 true,則應用樣式結構

數據條?

字段可選默認值描述
type'dataBar'
priorityY<auto>確定樣式的優先順序
minLength0指定此條件格式范圍內最短數據條的長度
maxLength100指定此條件格式范圍內最長數據條的長度
showValuetrue指定條件格式范圍內的單元格是否同時顯示數據條和數值或數據條
gradienttrue指定數據條是否具有漸變填充
bordertrue指定數據條是否有邊框
negativeBarColorSameAsPositivetrue指定數據條是否具有與正條顏色不同的負條顏色
negativeBarBorderColorSameAsPositivetrue指定數據條的負邊框顏色是否不同于正邊框顏色
axisPosition‘auto’指定數據條的軸位置
direction‘leftToRight’指定數據條的方向
cfvo2 到 5 個條件格式化值對象的數組,指定值范圍內的航路點
style如果比較返回 true,則應用樣式結構

包含文字?

屬性可選默認值描述
type'containsText'
priorityY<auto>確定樣式的優先順序
operator文本比較類型
text要搜索的文本
style如果比較返回 true,則應用樣式結構

包含文本運算符

運算符描述
containsText如果單元格值包含在 text 字段中指定的值,則應用格式
containsBlanks如果單元格值包含空格,則應用格式
notContainsBlanks如果單元格值不包含空格,則應用格式
containsErrors如果單元格值包含錯誤,則應用格式
notContainsErrors如果單元格值不包含錯誤,則應用格式

時間段?

屬性可選默認值描述
type'timePeriod'
priorityY<auto>確定樣式的優先順序
timePeriod比較單元格值的時間段
style如果比較返回 true,則應用樣式結構

時間段

時間段描述
lastWeek如果單元格值落在最后一周內,則應用格式
thisWeek如果單元格值在本周下降,則應用格式
nextWeek如果單元格值在下一周下降,則應用格式
yesterday如果單元格值等于昨天,則應用格式
today如果單元格值等于今天,則應用格式
tomorrow如果單元格值等于明天,則應用格式
last7Days如果單元格值在過去7天之內,則應用格式
lastMonth如果單元格值屬于上個月,則應用格式
thisMonth如果單元格值在本月下降,則應用格式
nextMonth如果單元格值在下個月下降,則應用格式

大綱級別?

Excel 支持大綱;行或列可以根據用戶希望查看的詳細程度展開或折疊。

大綱級別可以在列設置中定義:

worksheet.columns = [{ header: 'Id', key: 'id', width: 10 },{ header: 'Name', key: 'name', width: 32 },{ header: 'D.O.B.', key: 'DOB', width: 10, outlineLevel: 1 }
];

或直接在行或列上

worksheet.getColumn(3).outlineLevel = 1;
worksheet.getRow(3).outlineLevel = 1;

工作表大綱級別可以在工作表上設置

// 設置列大綱級別
worksheet.properties.outlineLevelCol = 1;// 設置行大綱級別
worksheet.properties.outlineLevelRow = 1;

注意:調整行或列上的大綱級別或工作表上的大綱級別將產生副作用,即還修改受屬性更改影響的所有行或列的折疊屬性。 例如。:

worksheet.properties.outlineLevelCol = 1;worksheet.getColumn(3).outlineLevel = 1;
expect(worksheet.getColumn(3).collapsed).to.be.true;worksheet.properties.outlineLevelCol = 2;
expect(worksheet.getColumn(3).collapsed).to.be.false;

大綱屬性可以在工作表上設置

worksheet.properties.outlineProperties = {summaryBelow: false,summaryRight: false,
};

圖片?

將圖像添加到工作表是一個分為兩個步驟的過程。首先,通過 addImage() 函數將圖像添加到工作簿中,該函數還將返回 imageId 值。然后,使用 imageId,可以將圖像作為平鋪背景或覆蓋單元格區域添加到工作表中。

注意:從此版本開始,不支持調整或變換圖像。

將圖片添加到工作簿?

Workbook.addImage 函數支持按文件名或按 Buffer 添加圖像。請注意,在兩種情況下,都必須指定擴展名。有效的擴展名包括 “jpeg”,“png”,“gif”。

// 通過文件名將圖像添加到工作簿
const imageId1 = workbook.addImage({filename: 'path/to/image.jpg',extension: 'jpeg',
});// 通過 buffer 將圖像添加到工作簿
const imageId2 = workbook.addImage({buffer: fs.readFileSync('path/to.image.png'),extension: 'png',
});// 通過 base64  將圖像添加到工作簿
const myBase64Image = "data:image/png;base64,iVBORw0KG...";
const imageId2 = workbook.addImage({base64: myBase64Image,extension: 'png',
});

將圖片添加到工作表背景?

使用 Workbook.addImage 中的圖像 ID,可以使用 addBackgroundImage 函數設置工作表的背景

// 設置背景
worksheet.addBackgroundImage(imageId1);

在一定范圍內添加圖片?

使用 Workbook.addImage 中的圖像 ID,可以將圖像嵌入工作表中以覆蓋一定范圍。從該范圍計算出的坐標將覆蓋從第一個單元格的左上角到第二個單元格的右下角。

// 在 B2:D6 上插入圖片
worksheet.addImage(imageId2, 'B2:D6');

使用結構而不是范圍字符串,可以部分覆蓋單元格。

請注意,為此使用的坐標系基于零,因此 A1 的左上角將為 {col:0,row:0}。單元格的分數可以通過使用浮點數來指定,例如 A1 的中點是 {col:0.5,row:0.5}

// 在 B2:D6 的一部分上插入圖像
worksheet.addImage(imageId2, {tl: { col: 1.5, row: 1.5 },br: { col: 3.5, row: 5.5 }
});

單元格區域還可以具有屬性 "editAs",該屬性將控制將圖像錨定到單元格的方式。它可以具有以下值之一:

描述
undefined它指定使圖像將根據單元格移動和調整其大小
oneCell這是默認值。圖像將與單元格一起移動,但大小不變動
absolute圖像將不會隨著單元格移動或調整大小
ws.addImage(imageId, {tl: { col: 0.1125, row: 0.4 },br: { col: 2.101046875, row: 3.4 },editAs: 'oneCell'
});

將圖片添加到單元格?

您可以將圖像添加到單元格,然后以 96dpi 定義其寬度和高度(以像素為單位)。

worksheet.addImage(imageId2, {tl: { col: 0, row: 0 },ext: { width: 500, height: 200 }
});

添加帶有超鏈接的圖片?

您可以將帶有超鏈接的圖像添加到單元格,并在圖像范圍內定義超鏈接。

worksheet.addImage(imageId2, {tl: { col: 0, row: 0 },ext: { width: 500, height: 200 },hyperlinks: {hyperlink: 'http://www.somewhere.com',tooltip: 'http://www.somewhere.com'}
});

工作表保護?

可以通過添加密碼來保護工作表免受修改。

await worksheet.protect('the-password', options);

工作表保護也可以刪除:

worksheet.unprotect();

有關如何修改單個單元格保護的詳細信息請查看 單元格保護。

注意:protect() 函數返回一個 Promise 代表它是異步的,當前的實現在主線程上運行,并且在 CPU 上將使用平均大約 600 毫秒。可以通過設置 spinCount 進行調整,該值可用于使過程更快或更有彈性。

工作表保護選項?

屬性默認值描述
selectLockedCellstrue允許用戶選擇鎖定的單元格
selectUnlockedCellstrue允許用戶選擇未鎖定的單元格
formatCellsfalse允許用戶格式化單元格
formatColumnsfalse允許用戶格式化列
formatRowsfalse允許用戶格式化行
insertRowsfalse允許用戶插入行
insertColumnsfalse允許用戶插入列
insertHyperlinksfalse允許用戶插入超鏈接
deleteRowsfalse允許用戶刪除行
deleteColumnsfalse允許用戶刪除列
sortfalse允許用戶對數據進行排序
autoFilterfalse允許用戶過濾表中的數據
pivotTablesfalse允許用戶使用數據透視表
spinCount100000保護或取消保護時執行的哈希迭代次數

文件 I/O?

XLSX?

讀 XLSX?
// 從文件讀取
const workbook = new Excel.Workbook();
await workbook.xlsx.readFile(filename);
// ... 使用 workbook// 從流讀取
const workbook = new Excel.Workbook();
await workbook.xlsx.read(stream);
// ... 使用 workbook// 從 buffer 加載
const workbook = new Excel.Workbook();
await workbook.xlsx.load(data);
// ... 使用 workbook
寫 XLSX
// 寫入文件
const workbook = createAndFillWorkbook();
await workbook.xlsx.writeFile(filename);// 寫入流
await workbook.xlsx.write(stream);// 寫入 buffer
const buffer = await workbook.xlsx.writeBuffer();

CSV?

讀 CSV?

讀取 CSV 文件時支持的選項。

屬性是否需要類型描述
dateFormatsNArray指定 dayjs 的日期編碼格式。
mapNFunction自定義Array.prototype.map() 回調函數,用于處理數據。
sheetNameNString指定工作表名稱。
parserOptionsNObjectparseOptions 選項 @fast-csv/format 模塊以寫入 csv 數據。
// 從文件讀取
const workbook = new Excel.Workbook();
const worksheet = await workbook.csv.readFile(filename);
// ... 使用 workbook 或 worksheet// 從流中讀取
const workbook = new Excel.Workbook();
const worksheet = await workbook.csv.read(stream);
// ... 使用 workbook 或 worksheet// 從帶有歐洲日期的文件中讀取
const workbook = new Excel.Workbook();
const options = {dateFormats: ['DD/MM/YYYY']
};
const worksheet = await workbook.csv.readFile(filename, options);
// ... 使用 workbook 或 worksheet// 從具有自定義值解析的文件中讀取
const workbook = new Excel.Workbook();
const options = {map(value, index) {switch(index) {case 0:// 第1列是字符串return value;case 1:// 第2列是日期return new Date(value);case 2:// 第3列是公式值的JSONreturn JSON.parse(value);default:// 其余的是數字return parseFloat(value);}},// https://c2fo.github.io/fast-csv/docs/parsing/optionsparserOptions: {delimiter: '\t',quote: false,},
};
const worksheet = await workbook.csv.readFile(filename, options);
// ... 使用 workbook 或 worksheet

CSV 解析器使用 fast-csv 讀取CSV文件。傳遞給上述寫入函數的選項中的 formatterOptions 將傳遞給 @fast-csv/format 模塊以寫入 csv 數據。 有關詳細信息,請參閱 fast-csv README.md。

使用 npm 模塊 dayjs 解析日期。如果未提供 dateFormats 數組,則使用以下 dateFormats:

  • ‘YYYY-MM-DD[T]HH:mm:ss’
  • ‘MM-DD-YYYY’
  • ‘YYYY-MM-DD’

請參閱 dayjs CustomParseFormat 插件,以獲取有關如何構造 dateFormat 的詳細信息。

寫 CSV?

寫入 CSV 文件時支持的選項。

屬性是否需要類型描述
dateFormatNString指定 dayjs 的日期編碼格式。
dateUTCNBoolean指定 ExcelJS 是否使用dayjs.utc()轉換時區以解析日期。
encodingNString指定文件編碼格式。
includeEmptyRowsNBoolean指定是否可以寫入空行。
mapNFunction自定義Array.prototype.map() 回調函數,用于處理行值。
sheetNameNString指定工作表名稱。
sheetIdNNumber指定工作表 ID。
formatterOptionsNObjectformatterOptions 選項 @fast-csv/format 模塊寫入csv 數據。

// 寫入文件
const workbook = createAndFillWorkbook();
await workbook.csv.writeFile(filename);// 寫入流
// 請注意,您需要提供 sheetName 或 sheetId 以正確導入到 csv
await workbook.csv.write(stream, { sheetName: 'Page name' });// 使用歐洲日期時間寫入文件
const workbook = new Excel.Workbook();
const options = {dateFormat: 'DD/MM/YYYY HH:mm:ss',dateUTC: true, // 呈現日期時使用 utc
};
await workbook.csv.writeFile(filename, options);// 使用自定義值格式寫入文件
const workbook = new Excel.Workbook();
const options = {map(value, index) {switch(index) {case 0:// 第1列是字符串return value;case 1:// 第2列是日期return dayjs(value).format('YYYY-MM-DD');case 2:// 第3列是一個公式,只寫結果return value.result;default:// 其余的是數字return value;}},// https://c2fo.github.io/fast-csv/docs/formatting/optionsformatterOptions: {delimiter: '\t',quote: false,},
};
await workbook.csv.writeFile(filename, options);// 寫入新 buffer
const buffer = await workbook.csv.writeBuffer();

CSV 解析器使用 fast-csv 編寫 CSV 文件。傳遞給上述寫入函數的選項中的 formatterOptions 將傳遞給 @fast-csv/format 模塊以寫入 csv 數據。有關詳細信息,請參閱 fast-csv README.md。

日期使用 npm 模塊 dayjs 格式化。如果未提供 dateFormat,則使用 dayjs.ISO_8601。編寫 CSV 時,您可以提供布爾值 dateUTCtrue,以使 ExcelJS 解析日期,而無需使用 dayjs.utc() 自動轉換時區。

流式 I/O?

上面記錄的文件 I/O 需要在內存中建立整個工作簿,然后才能寫入文件。雖然方便,但是由于所需的內存量,它可能會限制文檔的大小。

流寫入器(或讀取器)在生成工作簿或工作表數據時對其進行處理,然后將其轉換為文件形式。通常,這在內存上效率要高得多,因為最終的內存占用量,甚至中間的內存占用量都比文檔版本要緊湊得多,尤其是當您考慮到行和單元格對象一旦提交就被銷毀時,尤其如此。

流式工作簿和工作表的接口幾乎與文檔版本相同,但實際存在一些細微差別:

  • 將工作表添加到工作簿后,將無法將其刪除。
  • 提交行后,將無法再訪問該行,因為該行將從工作表中刪除。
  • 不支持 unMergeCells()

請注意,可以在不提交任何行的情況下構建整個工作簿。提交工作簿后,所有添加的工作表(包括所有未提交的行)將自動提交。但是,在這種情況下,與文檔版本相比收效甚微。

流式 XLSX?
流式 XLSX 寫入器?

流式 XLSX 寫入器在 ExcelJS.stream.xlsx 命名空間中可用。

構造函數采用帶有以下字段的可選 options 對象:

字段描述
stream指定要寫入 XLSX 工作簿的可寫流。
filename如果未指定流,則此字段指定要寫入 XLSX 工作簿的文件的路徑。
useSharedStrings指定是否在工作簿中使用共享字符串。默認為 false
useStyles指定是否將樣式信息添加到工作簿。樣式會增加一些性能開銷。默認為 false
zipExcelJS 內部傳遞給 Archiver 的 Zip選項。默認值為 undefined

如果在選項中未指定 streamfilename,則工作簿編寫器將創建一個 StreamBuf 對象,該對象將 XLSX 工作簿的內容存儲在內存中。可以通過屬性 workbook.stream 訪問此 StreamBuf 對象,該對象可用于通過 stream.read() 直接訪問字節,或將內容通過管道傳輸到另一個流。

// 使用樣式和共享字符串構造流式 XLSX 工作簿編寫器
const options = {filename: './streamed-workbook.xlsx',useStyles: true,useSharedStrings: true
};
const workbook = new Excel.stream.xlsx.WorkbookWriter(options);

通常,流式 XLSX 寫入器的接口與上述文檔工作簿(和工作表)相同,實際上行,單元格和樣式對象是相同的。

但是有一些區別…

構造

如上所示,WorkbookWriter 通常將要求在構造函數中指定輸出流或文件。

提交數據

當工作表行準備就緒時,應將其提交,以便可以釋放行對象和內容。通常,這將在添加每一行時完成…

worksheet.addRow({id: i,name: theName,etc: someOtherDetail
}).commit();

WorksheetWriter 在添加行時不提交行的原因是允許單元格跨行合并:

worksheet.mergeCells('A1:B2');
worksheet.getCell('A1').value = 'I am merged';
worksheet.getCell('C1').value = 'I am not';
worksheet.getCell('C2').value = 'Neither am I';
worksheet.getRow(2).commit(); // now rows 1 and two are committed.

每個工作表完成后,還必須提交:

// 完成添加數據。 提交工作表
worksheet.commit();

要完成 XLSX 文檔,必須提交工作簿。 如果未提交工作簿中的任何工作表,則將在工作簿提交中自動提交它們。

// 完成 workbook.
await workbook.commit();
// ... 流已被寫入
流式 XLSX 閱讀器?

流式 XLSX 工作簿閱讀器可以在ExcelJS.stream.xlsx命名空間中找到。

構造函數包含必需的輸入參數和可選的options參數:

ArgumentDescription
input (必需的)指定從中讀取XLSX工作簿的文件或可讀流的名稱
options (可選的)指定如何處理讀取解析期間發生的事件類型
options.entries指定是否去觸發事件('emit')或者不發出事件('ignore'),默認值是'emit'
options.sharedStrings指定是否去緩存('cache')共享字符串,將其插入到相應的單元格值中,或者是否去觸發('emit')或忽略('ignore')它們,在這兩種情況下,單元格值都將是對共享字符串索引的引用。默認值是'cache'
options.hyperlinks指定是否去緩存超鏈接('cache'),將其插入到相應的單元格值中,是否去觸發('emit')或忽略('ignore')它們。默認值是'cache'
options.styles指定是否去緩存樣式('cache'),將其插入到相應的行或單元格值中,或是否忽略('忽略')它們。默認值是'cache'
options.worksheets指定是否去觸發('emit')或忽略('ignore')工作表。默認值是'emit'
const workbook = new ExcelJS.stream.xlsx.WorkbookReader('./file.xlsx');
for await (const worksheetReader of workbookReader) {for await (const row of worksheetReader) {// ...}
}

請注意,由于性能原因,worksheetReader返回一個行數組,而不是單獨返回每一行: https://github.com/nodejs/node/issues/31979

迭代遍歷所有事件?

工作簿上的事件是 ‘worksheet’、‘shared-strings’ 和 ‘hyperlinks’。 工作表上的事件是 ‘row’ 和 ‘hyperlinks’.

const options = {sharedStrings: 'emit',hyperlinks: 'emit',worksheets: 'emit',
};
const workbook = new ExcelJS.stream.xlsx.WorkbookReader('./file.xlsx', options);
for await (const {eventType, value} of workbook.parse()) {switch (eventType) {case 'shared-strings':// 值是共享字符串case 'worksheet':// 值是worksheetReadercase 'hyperlinks':// 值是hyperlinksReader}
}
可讀流?

我們強烈建議使用異步迭代,但我們也公開了流接口以實現向后兼容性。

const options = {sharedStrings: 'emit',hyperlinks: 'emit',worksheets: 'emit',
};
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader('./file.xlsx', options);
workbookReader.read();workbookReader.on('worksheet', worksheet => {worksheet.on('row', row => {});
});workbookReader.on('shared-strings', sharedString => {// ...
});workbookReader.on('hyperlinks', hyperlinksReader => {// ...
});workbookReader.on('end', () => {// ...
});
workbookReader.on('error', (err) => {// ...
});

瀏覽器?

該庫的一部分已被隔離,并經過測試可在瀏覽器環境中使用。

由于工作簿讀寫器的流式傳輸性質,因此未包括這些內容。只能使用基于文檔的工作簿(有關詳細信息,請參見 創建工作簿)。

例如,在瀏覽器中使用 ExcelJS 的代碼可查看 github 中的 spec / browser 文件夾。

預捆綁?

以下文件已預先捆綁在一起,并包含在 dist 文件夾中。

  • exceljs.js
  • exceljs.min.js

值類型?

支持以下值類型。

Null 值?

Enum: Excel.ValueType.Null

空值表示沒有值,通常在寫入文件時將不存儲(合并的單元格除外)。可用于從單元格中刪除該值。例如:

worksheet.getCell('A1').value = null;

合并單元格?

Enum: Excel.ValueType.Merge

合并單元格是其值綁定到另一個“主”單元格的單元格。分配給合并單元將導致修改單元格。

數字值?

Enum: Excel.ValueType.Number

一個數字值。

例如:

worksheet.getCell('A1').value = 5;
worksheet.getCell('A2').value = 3.14159;

字符串值?

Enum: Excel.ValueType.String

一個簡單的文本字符串。

例如:

worksheet.getCell('A1').value = 'Hello, World!';

日期值?

Enum: Excel.ValueType.Date

日期值,由 JavaScript Date 類型表示。

例如:

worksheet.getCell('A1').value = new Date(2017, 2, 15);

超鏈接值?

Enum: Excel.ValueType.Hyperlink

具有文本和鏈接值的 URL。

例如:

// 鏈接到網絡
worksheet.getCell('A1').value = {text: 'www.mylink.com',hyperlink: 'http://www.mylink.com',tooltip: 'www.mylink.com'
};// 內部鏈接
worksheet.getCell('A1').value = { text: 'Sheet2', hyperlink: '#\'Sheet2\'!A1' };

公式值?

Enum: Excel.ValueType.Formula

一個 Excel 公式,用于即時計算值。請注意,雖然單元格類型將為“公式”,但該單元格可能具有一個有效類型值,該值將從結果值中得出。

請注意,ExcelJS 無法處理公式以生成結果,必須提供該公式。

例如:

worksheet.getCell('A3').value = { formula: 'A1+A2', result: 7 };

單元格還支持便捷的獲取器,以訪問公式和結果:

worksheet.getCell('A3').formula === 'A1+A2';
worksheet.getCell('A3').result === 7;

共享公式?

共享的公式通過減少工作表 xml 中文本的重復來增強 xlsx 文檔的壓縮。范圍中左上角的單元格是指定的母版,它將保留該范圍內的所有其他單元格都將引用的公式。然后,其他“從屬”單元格可以引用此主單元格,而不必再次重新定義整個公式。請注意,主公式將以常用的 Excel 方式轉換為從屬單元格,以便對其他單元格的引用將根據從屬單元相對于主單元的偏移量向右下移。例如:如果主單元格A2具有引用A1的公式,則如果單元格B2共享A2的公式,則它將引用B1。

可以將主公式與該范圍內的從屬單元格一起分配給該單元格

worksheet.getCell('A2').value = {formula: 'A1',result: 10,shareType: 'shared',ref: 'A2:B3'
};

可以使用新的值形式將共享公式分配給單元格:

worksheet.getCell('B2').value = { sharedFormula: 'A2', result: 10 };

這指定單元格B2是將從A2中的公式派生的公式,其結果為10。

公式便捷獲取器會將A2中的公式轉換為B2中應具有的公式:

expect(worksheet.getCell('B2').formula).to.equal('B1');

可以使用 fillFormula 方法將共享的公式分配到工作表中:

// 將 A1 設置為起始編號
worksheet.getCell('A1').value = 1;// 從 A1 開始以遞增計數將 A2 填充到 A10
worksheet.fillFormula('A2:A10', 'A1+1', [2,3,4,5,6,7,8,9,10]);

fillFormula 也可以使用回調函數來計算每個單元格的值

// 從A1開始以遞增計數將 A2 填充到 A100
worksheet.fillFormula('A2:A100', 'A1+1', (row, col) => row);

公式類型?

要區分真正的和轉換后的公式單元格,請使用 FormulaType getter:

worksheet.getCell('A3').formulaType === Enums.FormulaType.Master;
worksheet.getCell('B3').formulaType === Enums.FormulaType.Shared;

公式類型具有以下值:

名稱
Enums.FormulaType.None0
Enums.FormulaType.Master1
Enums.FormulaType.Shared2

數組公式?

在 Excel 中表示共享公式的一種新方法是數組公式。以這種形式,主單元格是唯一包含與公式有關的任何信息的單元格。它包含 shareType ‘array’ 以及適用于其的單元格范圍以及將要復制的公式。其余單元格是具有常規值的常規單元格。

注意:數組公式不會以共享公式的方式轉換。因此,如果主單元A2引用A1,則從單元B2也將引用A1。

例如:

// 將數組公式分配給 A2:B3
worksheet.getCell('A2').value = {formula: 'A1',result: 10,shareType: 'array',ref: 'A2:B3'
};// 可能沒有必要填寫工作表中的其余值

fillFormula 方法也可以用于填充數組公式

// 用數組公式 "A1" 填充 A2:B3
worksheet.fillFormula('A2:B3', 'A1', [1,1,1,1], 'array');

富文本值?

Enum: Excel.ValueType.RichText

樣式豐富的文本。

例如:

worksheet.getCell('A1').value = {richText: [{ text: 'This is '},{font: {italic: true}, text: 'italic'},]
};

布爾值?

Enum: Excel.ValueType.Boolean

例如:

worksheet.getCell('A1').value = true;
worksheet.getCell('A2').value = false;

錯誤值?

Enum: Excel.ValueType.Error

例如:

worksheet.getCell('A1').value = { error: '#N/A' };
worksheet.getCell('A2').value = { error: '#VALUE!' };

當前有效的錯誤文本值為:

名稱
Excel.ErrorValue.NotApplicable#N/A
Excel.ErrorValue.Ref#REF!
Excel.ErrorValue.Name#NAME?
Excel.ErrorValue.DivZero#DIV/0!
Excel.ErrorValue.Null#NULL!
Excel.ErrorValue.Value#VALUE!
Excel.ErrorValue.Num#NUM!

接口變化?

我們會盡一切努力創建一個良好的,一致的接口,該接口不會在版本之間不兼容,但令人遺憾的是,為了實現更大的利益,有時需要進行一些更改。

0.1.0?

Worksheet.eachRow?

Worksheet.eachRow 的回調函數中的參數已被交換和更改;它是 function(rowNumber,rowValues),現在是 function(row,rowNumber),使它的外觀更像 underscore(_.each)方法,并且行對象優先于行號。

Worksheet.getRow?

此函數已從返回稀疏的單元格數組更改為返回 Row 對象。這樣可以訪問行屬性,并有助于管理行樣式等。

仍可通過 Worksheet.getRow(rowNumber).values; 獲得稀疏的單元格值的數組。

0.1.1?

cell.model?

cell.styles 重命名為 cell.style

0.2.44?

從 Bluebird 切換到 Node 原生 Promise 的函數返回的 Promise 如果依賴 Bluebird 的額外功能,則可能會破壞調用代碼。

為了減少這種情況的出現,在0.3.0中添加了以下兩個更改:

  • 默認情況下使用功能更全且仍與瀏覽器兼容的 promise lib。 該庫支持 Bluebird 的許多功能,但占用空間少得多。
  • 注入其他 Promise 實現的選項。有關更多詳細信息,請參見配置部分。

配置?

ExcelJS現在支持對 Promise 庫的依賴項注入。您可以通過在模塊中包含以下代碼來還原 Bluebird Promise。

ExcelJS.config.setValue('promise', require('bluebird'));

請注意:我已經使用 bluebird 專門測試了 ExcelJS(直到最近,這是它使用的庫)。根據我所做的測試,它不適用于 Q。

注意事項?

Dist 文件夾?

在發布此模塊之前,先對源代碼進行編譯和其他處理,然后再將它們放置在 dist/ 文件夾中。該自述文件標識兩個文件-瀏覽器捆綁和壓縮版本。除了在 package.json 中指定為 "main" 的文件外,不能保證 dist/ 文件夾的其他內容。

已知的問題?

使用 Puppeteer 進行測試?

該 lib 中包含的測試套件包括一個在無頭瀏覽器中執行的小腳本,以驗證捆綁的軟件包。 在撰寫本文時,其表現出該測試在 Windows Linux 子系統中不能很好地進行。

因此,可以通過存在名為 .disable-test-browser 的文件來禁用瀏覽器測試。

sudo apt-get install libfontconfig

拼接與合并?

如果任何 splice 操作影響合并的單元格,則合并組將無法正確移動

發布歷史?

VersionChanges
0.0.9
  • Number Formats
0.1.0
  • Bug Fixes
    • “<” and “>” text characters properly rendered in xlsx
  • Better Column control
  • Better Row control
0.1.1
  • Bug Fixes
    • More textual data written properly to xml (including text, hyperlinks, formula results and format codes)
    • Better date format code recognition
  • Cell Font Style
0.1.2
  • Fixed potential race condition on zip write
0.1.3
  • Cell Alignment Style
  • Row Height
  • Some Internal Restructuring
0.1.5
  • Bug Fixes
    • Now handles 10 or more worksheets in one workbook
    • theme1.xml file properly added and referenced
  • Cell Borders
0.1.6
  • Bug Fixes
    • More compatible theme1.xml included in XLSX file
  • Cell Fills
0.1.8
  • Bug Fixes
    • More compatible theme1.xml included in XLSX file
    • Fixed filename case issue
  • Cell Fills
0.1.9
  • Bug Fixes
    • Added docProps files to satisfy Mac Excel users
    • Fixed filename case issue
    • Fixed worksheet id issue
  • Core Workbook Properties
0.1.10
  • Bug Fixes
    • Handles File Not Found error
  • CSV Files
0.1.11
  • Bug Fixes
    • Fixed Vertical Middle Alignment Issue
  • Row and Column Styles
  • Worksheet.eachRow supports options
  • Row.eachCell supports options
  • New function Column.eachCell
0.2.0
  • Streaming XLSX Writer
    • At long last ExcelJS can support writing massive XLSX files in a scalable memory efficient manner. Performance has been optimised and even smaller spreadsheets can be faster to write than the document writer. Options have been added to control the use of shared strings and styles as these can both have a considerable effect on performance
  • Worksheet.lastRow
    • Access the last editable row in a worksheet.
  • Row.commit()
    • For streaming writers, this method commits the row (and any previous rows) to the stream. Committed rows will no longer be editable (and are typically deleted from the worksheet object). For Document type workbooks, this method has no effect.
0.2.2
  • One Billion Cells
    • Achievement Unlocked: A simple test using ExcelJS has created a spreadsheet with 1,000,000,000 cells. Made using random data with 100,000,000 rows of 10 cells per row. I cannot validate the file yet as Excel will not open it and I have yet to implement the streaming reader but I have every confidence that it is good since 1,000,000 rows loads ok.
0.2.3
  • Bug Fixes
    • Merge Cell Styles
      • Merged cells now persist (and parse) their styles.
  • Streaming XLSX Writer
    • At long last ExcelJS can support writing massive XLSX files in a scalable memory efficient manner. Performance has been optimised and even smaller spreadsheets can be faster to write than the document writer. Options have been added to control the use of shared strings and styles as these can both have a considerable effect on performance
  • Worksheet.lastRow
    • Access the last editable row in a worksheet.
  • Row.commit()
    • For streaming writers, this method commits the row (and any previous rows) to the stream. Committed rows will no longer be editable (and are typically deleted from the worksheet object). For Document type workbooks, this method has no effect.
0.2.4
  • Bug Fixes
    • Worksheets with Ampersand Names
      • Worksheet names are now xml-encoded and should work with all xml compatible characters
  • Row.hidden & Column.hidden
    • Rows and Columns now support the hidden attribute.
  • Worksheet.addRows
    • New function to add an array of rows (either array or object form) to the end of a worksheet.
0.2.6
  • Bug Fixes
    • invalid signature: 0x80014: Thanks to hasanlussa for the PR
  • Defined Names
    • Cells can now have assigned names which may then be used in formulas.
  • Converted Bluebird.defer() to new Bluebird(function(resolve, reject){}). Thanks to user Nishchit for the Pull Request
0.2.7
  • Data Validations
    • Cells can now define validations that controls the valid values the cell can have
0.2.8
  • Rich Text Value
    • Cells now support in-cell formatting - Thanks to Peter ADAM
  • Fixed typo in README - Thanks to MRdNk
  • Fixing emit in worksheet-reader - Thanks to Alan Gunning
  • Clearer Docs - Thanks to miensol
0.2.9
  • Fixed "read property ‘richText’ of undefined error. Thanks to james075
0.2.10
  • Refactoring Complete. All unit and integration tests pass.
0.2.11
  • Outline Levels. Thanks to cricri for the contribution.
  • Worksheet Properties
  • Further refactoring of worksheet writer.
0.2.12
  • Sheet Views. Thanks to cricri again for the contribution.
0.2.13
  • Fix for exceljs might be vulnerable for regular expression denial of service. Kudos to yonjah and Josh Emerson for the resolution.
  • Fix for Multiple Sheets opens in ‘Group’ mode in Excel. My bad - overzealous sheet view code.
  • Also fix for empty sheet generating invalid xlsx.
0.2.14
  • Fix for exceljs might be vulnerable for regular expression denial of service. Kudos to yonjah and Josh Emerson for the resolution.
  • Fixed Multiple Sheets opens in ‘Group’ mode in Excel again. Added Workbook views.
  • Also fix for empty sheet generating invalid xlsx.
0.2.15
  • Added Page Setup Properties. Thanks to Jackkum for the PR
0.2.16
  • New Page Setup Property: Print Area
0.2.17
  • Merged Fix a bug on phonetic characters. This fixes an issue related to reading workbooks with phonetic text in. Note phonetic text is not properly supported yet - just properly ignored. Thanks to zephyrrider and gen6033 for the contribution.
0.2.18
  • Merged Fix regression #150: Stream API fails to write XLSX files. Apologies for the regression! Thanks to danieleds for the fix.
  • Merged Fix a bug on phonetic characters. This fixes an issue related to reading workbooks with phonetic text in. Note phonetic text is not properly supported yet - just properly ignored. Thanks to zephyrrider and gen6033 for the contribution.
0.2.19
  • Merged Update xlsx.js #119. This should make parsing more resilient to open-office documents. Thanks to nvitaterna for the contribution.
0.2.20
  • Merged Changes from exceljs/exceljs#127 applied to latest version #179. Fixes parsing of defined name values. Thanks to agdevbridge and priitliivak for the contribution.
0.2.21
  • Merged color tabs for worksheet-writer #135. Modified the behaviour to print deprecation warning as tabColor has moved into options.properties. Thanks to ethanlook for the contribution.
0.2.22
  • Merged Throw legible error when failing Value.getType() #136. Thanks to wulfsolter for the contribution.
  • Honourable mention to contributors whose PRs were fixed before I saw them:
    • haoliangyu
    • wulfsolter
0.2.23
  • Merged Fall back to JSON.stringify() if unknown Cell.Type #137 with some modification. If a cell value is assigned to an unrecognisable javascript object, the stored value in xlsx and csv files will be JSON stringified. Note that if the file is read again, no attempt will be made to parse the stringified JSON text. Thanks to wulfsolter for the contribution.
0.2.24
  • Merged Protect cell fix #166. This does not mean full support for protected cells merely that the parser is not confused by the extra xml. Thanks to jayflo for the contribution.
0.2.25
  • Added functions to delete cells, rows and columns from a worksheet. Modelled after the Array splice method, the functions allow cells, rows and columns to be deleted (and optionally inserted). See Columns and Rows for details.
    Note: Not compatible with cell merges
0.2.26
  • Merged Update border-xform.js #184Border edges without style will be parsed and rendered as no-border. Thanks to skumarnk2 for the contribution.
0.2.27
  • Merged Pass views to worksheet-writer #187. Now also passes views to worksheet-writer. Thanks to Temetz for the contribution.
  • Merged Do not escape xml characters when using shared strings #189. Fixing bug in shared strings. Thanks to tkirda for the contribution.
0.2.28
  • Merged Fix tiny bug [Update hyperlink-map.js] #190Thanks to lszlkss for the contribution.
  • Merged fix typo on sheet view showGridLines option #196 “showGridlines” should have been “showGridLines”. Thanks to gadiaz1 for the contribution.
0.2.29
  • Merged Fire finish event instead of end event on write stream #199 and Listen for finish event on zip stream instead of middle stream #200. Fixes issues with stream completion events. Thanks to junajan for the contribution.
0.2.30
  • Merged Fix issue #178 #201. Adds the following properties to workbook:
    • title
    • subject
    • keywords
    • category
    • description
    • company
    • manager
    Thanks to stavenko for the contribution.
0.2.31
  • Merged Fix issue #163: the “spans” attribute of the row element is optional #203. Now xlsx parsing will handle documents without row spans. Thanks to arturas-vitkauskas for the contribution.
0.2.32
  • Merged Fix issue 206 #208. Fixes issue reading xlsx files that have been printed. Also adds “lastPrinted” property to Workbook. Thanks to arturas-vitkauskas for the contribution.
0.2.33
  • Merged Allow styling of cells with no value. #210. Includes Null type cells with style in the rendering parsing. Thanks to oferns for the contribution.
0.2.34
  • Merged Fix “Unexpected xml node in parseOpen” bug in LibreOffice documents for attributes dc:language and cp:revision #212. Thanks to jessica-jordan for the contribution.
0.2.35
  • Fixed Getting a column/row count #74. Worksheet now has rowCount and columnCount properties (and actual variants), Row has cellCount.
0.2.36
  • Merged Stream reader fixes #217. Thanks to kturney for the contribution.
0.2.37
  • Merged Fix output order of Sheet Properties #225. Thanks to keeneym for the contribution.
  • Merged remove empty worksheet[0] from _worksheets #231. Thanks to pookong for the contribution.
  • Merged do not skip empty string in shared strings so that indexes match #232. Thanks again to pookong for the contribution.
  • Merged use shared strings for streamed writes #233. Thanks again to pookong for the contribution.
0.2.38
  • Merged Add a comment for issue #216 #236. Thanks to jsalwen for the contribution.
  • Merged Start on support for 1904 based dates #237. Fixed date handling in documents with the 1904 flag set. Thanks to holm for the contribution.
0.2.39
  • Merged Stops Bluebird warning about unreturned promise #245. Thanks to robinbullocks4rb for the contribution.
  • Merged Added missing dependency: col-cache.js #247. Thanks to Manish2005 for the contribution.
0.2.42
  • Browser Compatible!
    • Well mostly. I have added a browser sub-folder that contains a browserified bundle and an index.js that can be used to generate another. See Browser section for details.
  • Fixed corrupted theme.xml. Apologies for letting that through.
  • Merged [BUGFIX] data validation formulae undefined #253. Thanks to jayflo for the contribution.
0.2.43
  • Merged added a (maybe partial) solution to issue 99. i wasn’t able to create an appropriate test #255. This fixes Too few data or empty worksheet generate malformed excel file #99. Thanks to mminuti for the contribution.
0.2.44
  • Reduced Dependencies.
    • Goodbye lodash, goodbye bluebird. Minified bundle is now just over half what it was in the first version.
0.2.45
  • Merged Sheets with hyperlinks and data validations are corrupted #256. Thanks to simon-stoic for the contribution.
0.2.46
  • Merged Exclude character controls from XML output. Fixes #234 #262. Thanks to holm for the contribution.
  • Merged Add support for identifier #259. This fixes Broken XLSX because of “vertical tab” ascii character in a cell #234. Thanks to NOtherDev for the contribution.
0.3.0
  • Addressed Breaking change removing bluebird #266. Appologies for any inconvenience.
  • Added Promise library dependency injection. See Config section for more details.
0.3.1
  • Merged Update dependencies #279. Thanks to holm for the contribution.
  • Merged Minor fixes for stream handling #267. Thanks to holm for the contribution.
  • Added automated tests in phantomjs for the browserified code.
0.4.0
  • Fixed issue Boolean cell with value =“true” is returned as 1 #278. The fix involved adding two new Call Value types:
    • Boolean Value
    • Error Value
    Note: Minor version has been bumped up to 4 as this release introduces a couple of interface changes:
    • Boolean cells previously will have returned 1 or 0 will now return true or false
    • Error cells that previously returned a string value will now return an error structure
  • Fixed issue Code correctness - setters don’t return a value #280.
  • Addressed issue v0.3.1 breaks meteor build #288.
0.4.1
  • Merged Add support for cp:contentStatus #285. Thanks to holm for the contribution.
  • Merged Fix Valid characters in XML (allow \n and \r when saving) #286. Thanks to Rycochet for the contribution.
  • Fixed hyperlink with query arguments corrupts workbook #275. The hyperlink target is not escaped before serialising in the xml.
0.4.2
  • Addressed the following issues:

    • White text and borders being changed to black #290
    • Losing formatting/pivot table from loaded file #261
    • Solid fill become black #272
    These issues are potentially caused by a bug that caused colours with zero themes, tints or indexes to be rendered and parsed incorrectly.

    Regarding themes: the theme files stored inside the xlsx container hold important information regarding colours, styles etc and if the theme information from a loaded xlsx file is lost, the results can be unpredictable and undesirable. To address this, when an ExcelJS Workbook parses an XLSX file, it will preserve any theme files it finds and include them when writing to a new XLSX. If this behaviour is not desired, the Workbook class exposes a clearThemes() function which will drop the theme content. Note that this behaviour is only implemented in the document based Workbook class, not the streamed Reader and Writer.

0.4.3
  • Merged Support error references in cell ranges #294. Thanks to holm for the contribution.
0.4.4
  • Merged Issue with copied cells #297. This merge adds support for shared formulas. Thanks to muscapades for the contribution.
0.4.6
  • Merged Correct spelling #304. Thanks to toanalien for the contribution.
  • Merged Added support for auto filters #306. This adds Auto Filters to the Worksheet. Thanks to C4rmond4i for the contribution.
  • Restored NodeJS 4.0.0 compatability by removing the destructuring code. My apologies for any inconvenience.
0.4.9
  • Switching to transpiled code for distribution. This will ensure compatability with 4.0.0 and above from here on. And it will also allow use of much more expressive JS code in the lib folder!
  • Basic Image Support!Images can now be added to worksheets either as a tiled background or stretched over a range. Note: other features like rotation, etc. are not supported yet and will reqeuire further work.
0.4.10
  • Merged Add missing Office Rels #319. Thanks goes to mauriciovillalobos for the contribution.
  • Merged Add printTitlesRow Support #320 Thanks goes to psellers89 for the contribution.
0.4.11
  • Merged Avoid error on anchor with no media #327. Thanks goes to holm for the contribution.
  • Merged Assortment of fixes for streaming read #332. Thanks goes to holm for the contribution.
0.4.12
  • Merged Don’t set address if hyperlink r:id is undefined #334. Thanks goes to holm for the contribution.
0.4.13
  • Merged Issue 296 #343. This fixes Issue with writing newlines #296. Thanks goes to holly-weisser for the contribution.
0.4.14
  • Merged Syntax highlighting added ? #350. Thanks goes to rmariuzzo for the contribution.
0.5.0
  • Merged Fix right to left issues #356. Fixes Add option to RTL file #72 and Adding an option to set RTL worksheet #126. Big thank you to alitaheri for this contribution.
0.5.1
  • Merged Fix #345 TypeError: Cannot read property ‘date1904’ of undefined #364. This fixes TypeError: Cannot read property ‘date1904’ of undefined #345. Thanks to Diluka for this contribution.
0.6.0
  • Merged Add rowBreaks feature. #389. Thanks to brucejo75 for this contribution.
0.6.1
  • Merged Guard null model fields - fix and tests #403. Thanks to thecjharries for this contribution. Also thanks to Ryc O’Chet for help with reviewing.
0.6.2
  • Merged Add some comments in readme according csv importing #396. Thanks to Michael Lelyakin for this contribution. Also thanks to planemar for help with reviewing. This also closes csv to stream doesn’t work #395.
0.7.0
  • Merged Impl <xdr:twoCellAnchor editAs=oneCell> #407. Thanks to Ocke Janssen and Kay Ramme for this contribution. This change allows control on how images are anchored to cells.
0.7.1
  • Merged Don’t break when attempting to import a zip file that’s not an Excel file (eg. .numbers) #423. Thanks to Andreas Lind for this contribution. This change makes exceljs more reslilient when opening non-excel files.
  • Merged Fixes #419 : Updates readme. #434. Thanks to Vishnu Kyatannawar for this contribution.
  • Merged Don’t break when docProps/core.xml contains a <cp:version> tag #436. Thanks to Andreas Lind for this contribution. This change handles core.xml files with empty version tags.
0.8.0
  • Merged Add Base64 Image support for the .addImage() method #442. Thanks to James W Mann for this contribution.
  • Merged update moment to 2.19.3 #453. Thanks to Markan Patel for this contribution.
0.8.1
  • Merged Additional information about font family property #457. Thanks to kayakyakr for this contribution.
  • Merged Fixes #458 #459. This fixes Add style to column causes it to be hidden #458. Thanks to Alexander James Phillips for this contribution.
0.8.2
  • Merged Don’t break when loading an Excel file containing a chartsheet #466. Thanks to Andreas Lind for this contribution.
  • Merged Hotfix/sheet order#257 #471. This fixes Sheet Order #257. Thanks to Robbi for this contribution.
0.8.3
  • Assimilated fix #79 outdated dependencies in unzip2. Thanks to Jules Sam. Randolph for starting this fix and a really big thanks to Alexander Kachkaev for finding the final solution.
0.8.4
  • Merged Round Excel date to nearest millisecond when converting to javascript date #479. Thanks to Benoit Jean for this contribution.
0.8.5
  • Merged Bug fix: wb.worksheets/wb.eachSheet caused getWorksheet(0) to return sheet #485. Thanks to mah110020 for this contribution.
0.9.0
  • Merged Feature/issue 424 #489. This fixes No way to control summaryBelow or summaryRight #424. Many thanks to Sarah for this contribution.
0.9.1
  • Merged add type definition #490. This adds type definitions to ExcelJS! Many thanks to taoqf for this contribution.
1.0.0
  • Merged Add Node 8 and Node 9 to continuous integration testing #494. Many thanks to Markan Patel for this contribution.
  • Merged Small README fix #508. Many thanks to Guilherme Bernal for this contribution.
  • Merged Add support for inlineStr, including rich text #501. Many thanks to linguamatics-pdenes and Rob Scott for their efforts towards this contribution. Since this change is technically a breaking change (the rendered XML for inline strings will change) I’m making this a major release!
1.0.1
  • Fixed spliceColumns problem when the number of columns are important #520.
1.0.2
  • Merged Loosen exceljs’s dependency requirements for moment #524. Many thanks to nicoladefranceschi for this contribution. This change addresses Ability to use external “moment” package #517.
1.1.0
  • Addressed Is there a way inserting values in columns. #514. Added a new getter/setter property to Column to get and set column values (see Columns for details).
1.1.1
  • Merged Include index.d.ts in published packages #532. To fix TypeScript definitions missing from npm package #525. Many thanks to Kagami Sascha Rosylight for this contribution.
1.1.2
  • Merged Don’t break when docProps/core.xml contains <cp:contentType /> #536. Many thanks to Andreas Lind (and reviewers) for this contribution.
1.1.3
  • Merged Try to handle the case where a <c> element is missing an r attribute #537. Many thanks to Andreas Lind for this contribution.
1.2.0
  • Merged Add dateUTC flag to CSV Writing #544. Many thanks to Zackery Griesinger for this contribution.
1.2.1
  • Merged worksheet name is writable #547. Many thanks to xzper for this contribution.
1.3.0
  • Merged Add CSV write buffer support #549. Many thanks to Jarom Loveridge for this contribution.
1.4.2
  • Merged Discussion: Customizable row/cell limit #541. Many thanks to Andreas Lind for this contribution.
1.4.3
  • Merged Get the right text out of hyperlinked formula cells #552. Many thanks to Andreas Lind and Christian Holm for this contribution.
1.4.5
  • Merged Add test case with a huge file #556. Many thanks to Andreas Lind and Christian Holm for this contribution.
1.4.6
  • Merged Update README.md to reflect correct functionality of row.addPageBreak() #557. Many thanks to RajDesai for this contribution.
  • Merged fix index.d.ts #558. Many thanks to Diluka for this contribution.
1.4.7
  • Merged List /xl/sharedStrings.xml in [Content_Types].xml only if one of the … #562. Many thanks to Priidik Vaikla for this contribution.
1.4.8
  • Merged List /xl/sharedStrings.xml in [Content_Types].xml only if one of the … #562. Many thanks to Priidik Vaikla for this contribution.
  • Fixed issue with above where shared strings were used but the content type was not added.
1.4.9
  • Merged List /xl/sharedStrings.xml in [Content_Types].xml only if one of the … #562. Many thanks to Priidik Vaikla for this contribution.
  • Fixed issue with above where shared strings were used but the content type was not added.
  • Fixed issue 1.4.8 broke writing Excel files with useSharedStrings:true #581.
1.4.10
  • Merged core-xform: Tolerate a missing cp: namespace for the coreProperties element #564. Many thanks to Andreas Lind for this contribution.
1.4.12
  • Merged Avoid error on malformed address #567. Many thanks to Andreas Lind for this contribution.
  • Merged Added a missing Promise<void> in index.d.ts #571. Many thanks to Gabriel Fournier for this contribution. This release should fix Is workbook.commit() still a promise or not #548
1.4.13
  • Merged Issue #488 #574. Many thanks to dljenkins for this contribution. This release should fix Invalid time value Exception #488.
1.5.0
  • Merged Sheet add state for hidden or show #577. Many thanks to Freddie Hsinfu Huang for this contribution. This release should fix hide worksheet and reorder sheets #226.
1.5.1
  • Merged Update index.d.ts #582. Many thanks to hankolsen for this contribution.
  • Merged Decode the x<4 hex chars> escape notation in shared strings #584. Many thanks to Andreas Lind for this contribution.
1.6.0
  • Added .html property to Cells to facilitate html-safe rendering. See Handling Individual Cells for details.
1.6.1
  • Merged Fix Issue #488 where dt is an invalid date format. #587 to fix Invalid time value Exception #488. Many thanks to Iliya Zubakin for this contribution.
1.6.2
  • Merged Fix Issue #488 where dt is an invalid date format. #587 to fix Invalid time value Exception #488. Many thanks to Iliya Zubakin for this contribution.
  • Merged drawing element must be below rowBreaks according to spec or corrupt worksheet #590 Many thanks to Liam Neville for this contribution.
1.6.3
  • Merged set type optional #595 Many thanks to taoqf for this contribution.
  • Merged Fix some xlsx stream read xlsx not in guaranteed order problem #578 Many thanks to KMethod for this contribution.
  • Merged Fix formatting issue in README #599 Many thanks to Vishnu Kyatannawar for this contribution.
1.7.0
  • Merged Ability to set tooltip for hyperlink #602 Many thanks to Kuznetsov Aleksey for this contribution.
1.8.0
  • Merged Fix misinterpreted ranges from <definedName> #636 Many thanks to Andreas Lind for this contribution.
  • Merged Add LGTM code quality badges #640 Many thanks to Xavier RENE-CORAIL for this contribution.
  • Merged Add type definition for Column.values #646 Many thanks to Emil Laine for this contribution. This fixes Column.values is missing TypeScript definitions #645.
  • Merged Update README.md with load() option #663 Many thanks to Joanna Walker for this contribution.
  • Merged fixed packages according to npm audit #677 Many thanks to Manuel Minuti for this contribution.
  • Merged Update index.d.ts #699 Many thanks to Ray Yen for this contribution.
  • Merged Replaced node-unzip-2 to unzipper package which is more robust #708 Many thanks to johnmalkovich100 for this contribution.
  • Merged Read worksheet hidden state #728 Many thanks to Dishu(Lester) Lyu for this contribution.
  • Merged add Worksheet.state typescript definition fix #714 #736 Many thanks to Ilyes Kechidi for this contribution. This fixes Worksheet State does not exist in index.d.ts #714.
1.9.0
  • Merged Improvements for images (correct reading/writing possitions) #702. This fixes Image location don’t respect Column width #650 and Image position - stretching image #467. Many thanks to Siemienik Pawe? for this contribution.
1.9.1
  • Merged Add Typescript support for formulas without results #619. Many thanks to Loursin for this contribution.
  • Merged Fix existing row styles when using spliceRows #737. Many thanks to cxam for this contribution.
  • Merged Consistent code quality #774. Many thanks to Andreas Lubbe for this contribution.
1.10.0
  • Fixed effect of splicing rows and columns on defined names
  • Merged Add support for adding images anchored to one cell #746. Many thanks to Karl von Randow for this contribution.
  • Merged Add vertical align property #758. Many thanks to MikeZyatkov for this contribution.
  • Merged Replace the temp lib to tmp #775. Many thanks to Ivan Sotnikov for this contribution.
  • Merged Replace the temp lib to tmp #775. Many thanks to Andreas Lubbe for this contribution.
  • Merged Update Worksheet.dimensions return type #793. Many thanks to Siemienik Pawe? for this contribution.
  • Merged One more types fix #795. Many thanks to Siemienik Pawe? for this contribution.
1.11.0
  • Merged Add the ability to bail out of parsing if the number of columns exceeds a given limit #776. Many thanks to Andreas Lind for this contribution.
  • Merged Add support for repeated columns on every page when printing. #799. Many thanks to Jasmin Auger for this contribution.
  • Merged Do not use a promise polyfill on modern setups #815. Many thanks to Andreas Lubbe for this contribution.
  • Merged copy LICENSE to the dist folder #807. Many thanks to Yuping Zuo for this contribution.
  • Merged Avoid unhandled rejection on XML parse error #813. Many thanks to Andreas Lind for this contribution.
1.12.0
  • Merged (chore) increment unzipper to 0.9.12 to address npm advisory 886 #819. Many thanks to Kreig Zimmerman for this contribution.
  • Merged docs(README): improve docs #817. Many thanks to Yuping Zuo for this contribution.
  • Merged add comment support #529 #823. Many thanks to ilimei for this contribution.

    This fixes the following issues:

    • Is it possible to add comment on a cell? #202
    • Add comment to cell #451
    • Excel add comment on cell #503
    • How to add Cell comment #529
    • Please add example to how I can insert comments for a cell #707
1.12.1
  • Merged fix issue with print area defined name corrupting file #822. Many thanks to Julia Donaldson for this contribution. This fixes issue Defined Names Break/Corrupt Excel File into Repair Mode #664.
  • Merged Only keep at most 31 characters for sheetname #831. Many thanks to Xuebin He for this contribution. This fixes issue Limit worksheet name length to 31 characters #398.
1.12.2
  • Merged add cn doc #834 and update cn doc #852. Many thanks to flydragon for this contribution.
  • Merged fix minor spelling mistake in readme #853. Many thanks to John Varga for this contribution.
  • Merged Fix defaultRowHeight not working #855. Many thanks to autukill for this contribution. This should fix row height doesn’t apply to row #422, The worksheet.properties.defaultRowHeight can’t work!! How to set the rows height, help!! #634 and Default row height doesn’t work ? #696.
  • Merged Always keep first font #854. Many thanks to Dmitriy Gusev for this contribution. This should fix document scale (width only) is different after read & write #816, Default font from source document can not be parsed. #833 and Wrong base font: hardcoded Calibri instead of font from the document #849.
1.13.0
  • Merged zip: allow tuning compression for performance or size #862. Many thanks to myfreeer for this contribution.
  • Merged Feat configure headers and footers #863. Many thanks to autukill for this contribution.
  • Fixed an issue with defaultRowHeight where the default value resulted in ‘customHeight’ property being set.
1.14.0
  • Merged Fix header and footer text format error in README.md #874. Many thanks to autukill for this contribution.
  • Added Tables. See Tables for details.
  • Merged fix: #877 and #880. Many thanks to Alexander Heinrich for this contribution. This fixes bug: Hyperlink without text crashes write #877 and bug: malformed comment crashes on write #880
1.15.0
  • Merged Add Compression level option to WorkbookWriterOptions for streaming #889. Many thanks to Alfredo Benassi for this contribution.
  • Merged Feature/Cell Protection #903 and Feature/Sheet Protection #907. Many thanks to karabaesh for these contributions.
2.0.1

Major Version Change

Introducing async/await to ExcelJS!

The new async and await features of JavaScript can help a lot to make code more readable and maintainable. To avoid confusion, particularly with returned promises from async functions, we have had to remove the Promise class configuration option and from v2 onwards ExcelJS will use native Promises. Since this is potentially a breaking change we’re bumping the major version for this release.

Changes

  • Merged Introduce async/await #829. Many thanks to Andreas Lubbe for this contribution.
  • Merged Update index.d.ts #930. Many thanks to cosmonovallc for this contributions.
  • Merged TS: Add types for addTable function #940. Many thanks to egmen for this contributions.
  • Merged added explicit return types to the type definitions of Worksheet.protect() and Worksheet.unprotect() #926. Many thanks to Tamas Czinege for this contributions.
  • Dropped dependencies on Promise libraries.
3.0.0

Another Major Version Change

Javascript has changed a lot over the years, and so have the modules and technologies surrounding it. To this end, this major version of ExcelJS changes the structure of the publish artefacts:

Main Export is now the Original Javascript Source

Prior to this release, the transpiled ES5 code was exported as the package main. From now on, the package main comes directly from the lib/ folder. This means a number of dependencies have been removed, including the polyfills.

ES5 and Browserify are Still Included

In order to support those that still require ES5 ready code (e.g. as dependencies in web apps) the source code will still be transpiled and available in dist/es5.

The ES5 code is also browserified and available as dist/exceljs.js or dist/exceljs.min.js

See the section Importing for details

3.1.0
  • Merged Uprev fast-csv to latest version which does not use unsafe eval #873. Many thanks to Mike Townsend for this contribution.
  • Merged Exclude Infinity on createInputStream #906. Many thanks to Sophie Kwon for this contribution.
  • Merged Feature/Add comments/notes to stream writer #911. Many thanks to brunoargolo for this contribution. This fixes Can’t add cell comment using streaming WorkbookWriter #868
  • Fixed an issue with reading .xlsx files containing notes. This should resolve the following issues:
    • Reading comment/note from xlsx #941
    • Excel.js doesn’t parse comments/notes. #944
3.2.0
  • Merged Add document for zip options of streaming WorkbookWriter #923. Many thanks to Soichi Takamura for this contribution.
  • Merged array formula #933. Many thanks to yoann-antoviaque for this contribution. This fixes broken array formula #932 and adds Array Formulae to ExcelJS.
3.3.0
  • Merged Fix anchor.js #892. Many thanks to Wojciech Wojtkowski for this contribution.
  • Merged add xml:space=“preserve” for all whitespaces #896. Many thanks to Sebastian Keller for this contribution.
  • Merged Add shrinkToFit to document and typing #959. Many thanks to (‘3’) for this contribution. This fixes shrinkToFit property not on documentation #943.
  • Merged #951: Force formula re-calculation on file open from Excel #980. Many thanks to zymon for this contribution. This fixes Force formula re-calculation on file open from Excel #951.
  • Fixed Lib contains class syntax, not compatible with IE11 #989.
3.3.1
  • Merged Add headerFooter to worksheet model when importing from file #1000. Many thanks to Kaiichiro Ota for this contribution.
  • Merged Update eslint plugins and configs #1005, Drop grunt-lib-phantomjs #1006 and Rename .browserslintrc.txt to .browserslistrc #1007. Many thanks to Takeshi Kurosawa for this contribution.
  • Merged Fix issue #988 #1012. This fixes Can not read excel file #988. Many thanks to Todd Hambley for this contribution.
3.4.0
  • Merged Feature/stream writer add background images #1016. Many thanks to brunoargolo for this contribution.
  • Merged Fix issue # 991 #1019. This fixes read csv file issue #991. Many thanks to Nathaniel J. Liberty for this contribution.
  • Merged Large excels - optimize performance of writing file by excelJS + optimize generated file (MS excel opens it much faster) #1018. Many thanks to Piotr for this contribution.
3.5.0
  • Conditional Formatting A subset of Excel Conditional formatting has been implemented! Specifically the formatting rules that do not require XML to be rendered inside an <extLst> node, or in other words everything except databar and three icon sets (3Triangles, 3Stars, 5Boxes). These will be implemented in due course
  • Merged remove core-js/ import #1030. Many thanks to jeffrey n. carre for this contribution. This change is used to create a new browserified bundle artefact that does not include any polyfills. See Browserify for details.
3.6.0
  • Merged 1041 multiple print areas #1042. Many thanks to Alexander Pruss for this contribution.
  • Merged fix typings for cell.note #1058. Many thanks to xydens for this contribution.
  • Conditional Formatting has been completed. The <extLst> conditional formattings including dataBar and the three iconSet types (3Triangles, 3Stars, 5Boxes) are now available.
3.6.1
  • Merged Clarify merging cells by row/column numbers #1047. Many thanks to Kendall Roth for this contribution.
  • Merged Fix README mistakes concerning freezing views #1048. Many thanks to overlookmotel for this contribution.
  • Merged:
    • fix issue #1045 horizontalCentered & verticalCentered in page not working #1073
    • Fix the problem of anchor failure of readme_zh.md file #1082
    • Fix problems caused by case of worksheet names #1065
    Many thanks to Alan Wang for this contribution.
3.7.0
  • Merged Fix Issue #1075: Unable to read/write defaultColWidth attribute in <sheetFormatPr> node #1076. Many thanks to Kaiichiro Ota for this contribution.
  • Merged function duplicateRows added #1078 and Duplicate rows #1088. Many thanks to cbeltrangomez84 for this contribution.
  • Merged Prevent from unhandled promise rejection durning workbook load #1087. Many thanks to Wojtek for this contribution.
  • Merged fix issue #899 Support for inserting pictures with hyperlinks #1071. Many thanks to Alan Wang for this contribution.
  • Merged Update TS definition to reference proper internal libraries #1089. Many thanks to Jesse Kawell for this contribution.
3.8.0
  • Merged Issue/Corrupt workbook using stream writer with background image #1090. Many thanks to brunoargolo for this contribution.
  • Merged Fix index.d.ts #1092. Many thanks to Siemienik Pawe? for this contribution.
  • Merged Wait for writing to tmp fiels before handling zip stream close #1093. Many thanks to Wojtek for this contribution.
  • Merged Support ArrayBuffer as an xlsx.load argument #1095. Many thanks to Wojtek for this contribution.
  • Merged Export shared strings with RichText #1099. Many thanks to Kaiichiro Ota for this contribution.
  • Merged Keep borders of merged cells after rewriting an Excel workbook #1102. Many thanks to Kaiichiro Ota for this contribution.
  • Merged Fix #1103: editAs not working #1104. Many thanks to Alan Wang for this contribution.
  • Merged Fix to issue #1101 #1105. Many thanks to Carlos Andres Beltran Gomez for this contribution.
  • Merged fix some errors and typos in readme #1107. Many thanks to Alan Wang for this contribution.
  • Merged Update issue templates #1112. Many thanks to Siemienik Pawe? for this contribution.
3.8.1
  • Merged Update issue templates #1112. Many thanks to Siemienik Pawe? for this contribution.
  • Merged Typo: Replace ‘allways’ with ‘always’ #1124. Many thanks to Siemienik Pawe? for this contribution.
  • Merged Replace uglify with terser #1125. Many thanks to Andreas Lubbe for this contribution.
  • Merged Apply codestyles on each commit and run lint:fix #1126. Many thanks to Andreas Lubbe for this contribution.
  • Merged [WIP] Replace sax with saxes #1127. Many thanks to Andreas Lubbe for this contribution.
  • Merged Add PR, Feature Request and Question github templates #1128. Many thanks to Andreas Lubbe for this contribution.
  • Merged fix issue #749 Fix internal link example errors in readme #1137. Many thanks to Alan Wang for this contribution.
3.8.2
  • Merged Update @types/node version to latest lts #1133. Many thanks to Siemienik Pawe? for this contribution.
  • Merged fix issue #1118 Adding Data Validation and Conditional Formatting to the same sheet causes corrupt workbook #1134. Many thanks to Alan Wang for this contribution.
  • Merged Add benchmarking #1139. Many thanks to Andreas Lubbe for this contribution.
  • Merged fix issue #731 image extensions not be case sensitive #1148. Many thanks to Alan Wang for this contribution.
  • Merged fix issue #1165 and update index.d.ts #1169. Many thanks to Alan Wang for this contribution.
3.9.0
  • Merged Optimize SAXStream #1140. Many thanks to Andreas Lubbe for this contribution.
  • Merged fix issue #1057 Fix addConditionalFormatting is not a function error when using Streaming XLSX Writer #1143. Many thanks to Alan Wang for this contribution.
  • Merged fix issue #204 sets default column width #1160. Many thanks to Alan Wang for this contribution.
  • Merged Include cell address for Shared Formula master must exist… error #1164. Many thanks to Brad Reed for this contribution.
  • Merged Typo in DataValidation examples #1166. Many thanks to Matthieu Ravey for this contribution.
  • Merged fixes #1175 #1176. Many thanks to Siemienik Pawe? for this contribution.
  • Merged fix issue #1178 and update index.d.ts #1179. Many thanks to Alan Wang for this contribution.
  • Merged Simple test if typescript is able to compile #1182. Many thanks to Siemienik Pawe? for this contribution.
  • Merged More improvements #1190. Many thanks to Andreas Lubbe for this contribution.
  • Merged Ensure all node_modules are compatible with IE11 #1193. Many thanks to Andreas Lubbe for this contribution.
  • Merged fix issue #1194 and update index.d.ts #1199. Many thanks to Alan Wang for this contribution. This fixes [BUG] TypeScript version doesn’t have definition for Worksheet.addConditionalFormatting #1194.
  • Merged fix issue #1157 marked Cannot set property #1204. Many thanks to Alan Wang for this contribution. This fixes [BUG] Cannot set property ‘marked’ of undefined #1157.
  • Merged Deprecate createInputStream #1209. Many thanks to Andreas Lubbe for this contribution.
  • Merged fix issue #1206 #1205 Abnormality of and attributes #1210. Many thanks to Alan Wang for this contribution. This fixes [BUG] Unlocked cells do not maintain their unlocked status after reading and writing a workbook. #1205 and [BUG] Unlocked cells lose their vertical and horizontal alignment after a read and write. #1206.
3.10.0
  • Merged [Chore] Upgrade dependencies #1233. Many thanks to Andreas Lubbe for this contribution.
  • Merged Fix issue #1198 Absolute path and relative path need to be compatible #1220. Many thanks to Alan Wang for this contribution. This fixes [BUG] Loading OpenPyXL workbooks #1198. Merged Upgrade tmp #1234. Many thanks to Andreas Lubbe for this contribution. This fixes Process doesn’t exit < 8.12.0 #882.
  • Merged New version of dayjs requires explicit Z in the date formats #1270. Many thanks to Andreas Lubbe for this contribution.
  • Merged Fixed #1276 #1280. Many thanks to Subhajit Das for this contribution. This fixes [BUG] Invalid regular expression: / 1$/: Range out of order in character class #1276. Merged [bugfix] Fix special cell values causing invalid files produced #1278. Many thanks to Alan Wang for this contribution. This fixes Special cell value results invalid file #703.
  • Merged Re-translation of simplified Chinese documents (zh-cn) #1208. Many thanks to 不如懷念 for this contribution.
  • Merged data-validations-xform: keep formulae if type not exists #1229. Many thanks to myfreeer for this contribution.
  • Merged WorkbookWriter support rowBreaks #1257. Many thanks to Alan Wang for this contribution. This fixes [BUG] WorkbookWriter doesn’t support headerFooter and rowBreaks. #1248.
  • Merged Fixed ascii only #1289. Many thanks to Subhajit Das for this contribution.
  • Merged Supports setting cell comment properties #1159. Many thanks to Alan Wang for this contribution.
  • Merged docs: add links to top with jump2header #1215. Many thanks to Drago? Str?inu for this contribution.
  • Merged Fix cell.text return an empty object when cell is empty #1310. Many thanks to Alan Wang for this contribution.
  • Merged Use rest args instead of slicing arguments #1303. Many thanks to Andreas Lubbe for this contribution.
4.0.1
  • A Major Version Change - The main ExcelJS interface has been migrated from streams based API to Async Iterators making for much cleaner code. While technically a breaking change, most of the API is unchanged For details see UPGRADE-4.0.md.
  • This upgrade has come from the following merges:
    • [MAJOR VERSION] Async iterators #1135
    • [MAJOR VERSION] Move node v8 support to ES5 imports #1142
    A lot of work from the team went into this - in particular Andreas Lubbe and Siemienik Pawe?.
4.1.0
  • Merged Remove const enum and add ErrorValue in index.d.ts #1317 Many thanks to Alex Plumley for this contribution.
  • Merged update README.md and READEME_zh.md #1319 Many thanks to Alan Wang for this contribution.
  • Merged Added insert rows functionality with new style inherit options #1324 Many thanks to Subhajit Das for this contribution.
  • Merged Updated readme for insert rows #1327 Many thanks to Subhajit Das for this contribution.
  • Merged Fix: Async iterators definition #1338 Many thanks to Julien - JuH for this contribution.
  • Merged [bugfix] Fix special cell values causing invalid files produced(#1339) #1344. This fixes [BUG] hasOwnProperty, constructor special words not serialized correctly with stream.xlsx.WorkbookWriter #1339. Many thanks to Alan Wang for this contribution.
  • Merged Fix the error that comment does not delete at spliceColumn #1334. Many thanks to sdg9670 for this contribution.
  • Merged bug fix can not read property date1904 of undefined #1328. Many thanks to 1328 for this contribution.
4.1.1
  • Merged update index.d.ts #1356 Many thanks to Siemienik Pawe? for this contribution.
  • Merged Fix styleOption error in index.ts #1358. This fixes [BUG] 4.1.0 causes TypeScript compilation errors - addRows styleOption should be optional? #1357. Many thanks to sdg9670 for this contribution.
  • Merged Improved documentation #1354 Many thanks to Subhajit Das for this contribution.
4.2.0
  • Merged Fix issue #1431 Streaming WorkbookReader _parseSharedStrings doesn’t handle rich text within shared string nodes #1432. Many thanks to Reza Heidari for this contribution.
  • Merged Change typing for colorScale colour to array of colours #1442. Many thanks to Leondro Lio for this contribution.
  • Merged AddRow/s and InsertRow/s now returning the newly added rows #1443. Many thanks to Subhajit Das for this contribution.
  • Merged fix docs #1475. Many thanks to Dmytro Kyba for this contribution.
  • Merged [bugfix]Fix Issue #1254 and update index.d.ts #1360. This should fix [BUG] getSheetValues() typescript definition is incorrect #1254. Many thanks to Alan Wang for this contribution.
  • Merged Fix issue #1261 WorkbookWriter sheet.protect() function doesn’t exist #1262. This should fix [BUG] WorkbookWriter sheet.protect() function doesn’t exist #1261. Many thanks to Reza Heidari for this contribution.
  • Merged README: images not supported in streaming mode #1405. Many thanks to Christian d’Heureuse for this contribution.
  • Merged Run linter with prettier 2 #1477. Many thanks to Andreas Lubbe for this contribution.
  • Merged Increase the performance of some xml and html helpers #1476. Many thanks to Andreas Lubbe for this contribution.
  • Merged Performance improvement in col-cache #1482. Many thanks to Kevin Kwok for this contribution.
  • Merged Fix type definition for DefinedNamesRanges #1481. Many thanks to Kevin Kwok for this contribution.
  • Merged Fixed undefined ref error when setting a data validation that is a range of cells at the worksheet level #1480. Many thanks to Bene-Graham for this contribution.
  • Merged add A3 paperSize number #1485. This should fix [F] The printing size can be set to A3 #1406. Many thanks to skypesky for this contribution.
  • Merged Fix #1364 Incorrect Worksheet Name on Streaming XLSX Reader #1478. This should fix [BUG] Incorrect Worksheet Name on Streaming XLSX Reader #1364. Many thanks to Kevin Kwok for this contribution.
  • Merged grunt: skip babel transpile for core-js #1466. Many thanks to myfreeer for this contribution.
  • Merged xlsx: use TextDecoder and TextEncoder in browser #1486. Many thanks to myfreeer for this contribution.
  • Merged Refine typing for Column #1488. This should fix [BUG] Typescript error from getColumn.eachCell #1120. Many thanks to Selwyn Yeow for this contribution.
  • Merged col-cache: optimize for performance #1489. Many thanks to myfreeer for this contribution.
  • Merged Add lastColumn property (fixes #1453) #1487. This should fix property of worsheet.lastcolumn #1453. Many thanks to FliegendeWurst for this contribution.
  • Merged Add a test for CSV writeFile encoding #1495. This should close [BUG] Export CSV garbled characters #1473. and Can’t get hebrew to display correctly in a generted CSV file #995. Many thanks to Joseph Dykstra for this contribution.
  • Merged Clarify encoding option is just for .writeFile #1496. Many thanks to Joseph Dykstra for this contribution.
  • Merged Merge cells after row insert #1377. Many thanks to Curt Commander for this contribution.
  • Merged Fix issue 1474 (to check invalid sheet name) #1484. This should fix [BUG] Incorrectly handles ‘/’, ‘:’ characters in sheet name #1474. Many thanks to skypesky for this contribution.
4.2.1
  • Merged Typing FillPattern fgColor should be optional #1550. Many thanks to Andries Smit for this contribution.
  • Merged Fixed return type on getRows #1564. Many thanks to Paul Mcilwaine for this contribution.
  • Merged fix #1598 lint violations #1599. Fixes [BUG] npm run lint reports multiple violations #1598. Many thanks to Ilya I for this contribution.
  • Merged Fix fullAddress row and col types #1606. Many thanks to Adam Eisenreich for this contribution.
4.3.0
  • Merged Add TS declarations of Workbook properties #1656. Many thanks to Tanawit Kritwongwiman for this contribution.
  • Merged Fix issue #178 #201. Many thanks to Vasiliy Stavenko for this contribution.
  • Merged doc: add example for solid pattern usage #1649. Many thanks to fpaupier for this contribution.
  • Merged Add type definition for lastColumn property (fixes #1453) #1629. Fixes Add type for property of worsheet.lastcolumn #1453. Many thanks to Daniel Gon?alves for this contribution.
  • Merged fix #1598 lint violations #1599. Fixes [BUG] npm run lint reports multiple violations #1598. Many thanks to Ilya I for this contribution.
  • Merged Update @types/node version to latest lts #1133. Fixes ERROR in node_modules/exceljs/index.d.ts(1648,34): error TS2503: Cannot find namespace ‘NodeJS’. #971 and ERROR in node_modules/exceljs/index.d.ts(1661,34): error TS2503: Cannot find namespace ‘NodeJS’. #997. Many thanks to Siemienik Pawel for this contribution.
  • Merged Added Node v16 to the test suite #1731. Many thanks to Alex Bj?rlig for this contribution.
  • Merged Readme moment to dayjs #1708. Many thanks to Jerebtw for this contribution.
  • Merged Ability to set tooltip for hyperlink #602. Many thanks to Aleksey Kuznetsov for this contribution.
  • Merged Fixed conditional format corrupting sheet #1305 #1574. Fixes [BUG] Errors when opening file in Excel after saving a file with conditional formatting #1305. Many thanks to Rolando Romero for this contribution.
  • Merged Improvements for images (correct reading/writing possitions) #702. Many thanks to Siemienik Pawel for this contribution.

  1. -í???€€-???e?€€-???? ??

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:
http://www.pswp.cn/diannao/82694.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/82694.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/82694.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

時空注意力機制深度解析:理論、技術與應用全景

時空注意力機制作為深度學習領域的關鍵技術&#xff0c;通過捕捉數據在時間和空間維度上的依賴關系&#xff0c;顯著提升了時序數據處理和時空建模能力。本文從理論起源、數學建模、網絡架構、工程實現到行業應用&#xff0c;系統拆解時空注意力機制的核心原理&#xff0c;涵蓋…

wxWidgets 3.2.8 發布,修復了GTK下,wxStaticText顯示文本異常的問題

詳細如下&#xff1a; 3.2.8 是穩定的 3.2 系列中的最新維護版本&#xff0c;現已在 GitHub 上提供&#xff0c;您可以從中下載帶有 所選 Windows 的庫源和文檔以及二進制文件 編譯器&#xff0c;例如 Microsoft Visual C、MinGW-w64 和 TDM-GCC。您還可以閱讀更新的文檔 版本&…

網頁Web端無人機直播RTSP視頻流,無需服務器轉碼,延遲300毫秒

隨著無人機技術的飛速發展&#xff0c;全球無人機直播應用市場也快速擴張&#xff0c;從農業植保巡檢到應急救援指揮&#xff0c;從大型活動直播到智慧城市安防&#xff0c;實時視頻傳輸已成為剛需。預計到2025年&#xff0c;全球將有超過1000萬架商用無人機搭載直播功能&#…

思維鏈框架:LLMChain,OpenAI,PromptTemplate

什么是思維鏈,怎么實現 目錄 什么是思維鏈,怎么實現思維鏈(Chain of Thought)在代碼中的實現方式1. 手動構建思維鏈提示2. 少樣本思維鏈提示3. 自動思維鏈生成4. 思維鏈與工具使用結合5. 使用現有思維鏈框架:LLMChain,OpenAI,PromptTemplate思維鏈實現的關鍵要點思維鏈(C…

杰理強制燒錄撥碼開關

5.3. 工具撥碼開關說明 — JL Project Documentation

智能手表關鍵技術評估報告

?? 智能手表關鍵技術評估報告 產品名稱:Aurora Watch S1 智能手表 編寫日期:2025年5月6日 版本號:v1.0 編寫人:XXX(技術負責人) 一、報告目的 本報告旨在對智能手表核心技術模塊進行全面評估,識別項目研發過程中可能存在的技術風險、供應鏈瓶頸和開發難點,并為架構…

基于RT-Thread驅動EEPROM_AD24C02

基于RT-Thread驅動EEPROM_AD24C02 前言一、硬件設計二、軟件設計三、測試1、eeprom_test&#xff08;&#xff09;測試2、基礎操作字節實驗3、多字節讀寫 前言 存儲容量2048位&#xff0c;內部組織256x8&#xff08;2K&#xff09;&#xff0c;即256個字節的存儲單元&#xff…

五、Hive表類型、分區及數據加載

在 Hive 中高效構建、管理和查詢數據倉庫&#xff0c;核心在于精準運用表類型&#xff08;內部/外部&#xff09;與分區策略&#xff08;靜態/動態/多重&#xff09;。這不僅決定數據的生命周期歸屬&#xff0c;更是優化海量數據查詢性能的關鍵手段。 一、表的身份權責&#x…

C++色彩博弈的史詩:紅黑樹

文章目錄 1.紅黑樹的概念2.紅黑樹的結構3.紅黑樹的插入4.紅黑樹的刪除5.紅黑樹與AVL樹的比較6.紅黑樹的驗證希望讀者們多多三連支持小編會繼續更新你們的鼓勵就是我前進的動力&#xff01; 紅黑樹是一種自平衡二叉查找樹&#xff0c;每個節點都帶有顏色屬性&#xff0c;顏色或為…

基于STM32、HAL庫的CH342F USB轉UART收發器 驅動程序設計

一、簡介: CH342F是一款USB轉串口芯片,由南京沁恒電子(WCH)生產,具有以下特點: 支持USB轉UART、IrDA紅外或SPI接口 內置時鐘,無需外部晶振 支持5V和3.3V電源電壓 最高支持3Mbps波特率 支持常用的MODEM聯絡信號 內置EEPROM,可配置設備VID/PID/序列號等 二、硬件接口: C…

項目功能-圖片清理(上)

一、圖片存儲介紹 在實際開發中&#xff0c;我們會有很多處理不同功能的服務器。例如&#xff1a; 應用服務器&#xff1a;負責部署我們的應用 數據庫服務器&#xff1a;運行我們的數據庫 文件服務器&#xff1a;負責存儲用戶上傳文件的服務器 分服務器處理的目的是讓服務…

創建三個網絡,分別使用RIP、OSPF、靜態,并每個網絡10個電腦。使用DHCP分配IP

DHCP 自動分配IP&#xff0c;集中管理&#xff0c;提高效率 在路由器中設置 Router>en Router#conf t Router(config)#ip dhcp pool ip30 //創建DHCP地址池 Router(dhcp-config)#network 192.168.30.0 255.255.255.0 // 配置網絡地址和子網掩碼 Router(dhcp-config)#defa…

如何使用 WMIC 命令在 Windows 11 或 10 上卸載軟件

如果您正在尋找一個命令提示符或 PowerShell 命令來卸載 Windows 應用程序,那么使用 wmic(Windows Management Instrumentation Command-line)是一種強大的技術,尤其是在處理難以卸載的程序或自動化卸載過程時。在本教程中,我們將學習如何使用 wmic 來卸載軟件。 先決條件…

FEKO許可證的安全與合規性

在電磁仿真領域&#xff0c;FEKO軟件因其出類拔萃的性能和廣泛的應用場景&#xff0c;贏得了全球用戶的廣泛贊譽。但在這背后&#xff0c;是什么讓FEKO在眾多競爭者中脫穎而出&#xff1f;答案是其許可證的安全與合規性。它們不僅為用戶提供了堅固的保障&#xff0c;更確保了用…

ESP32開發入門(九):HTTP服務器開發實踐

一、HTTP服務器基礎 1.1 什么是HTTP服務器&#xff1f; HTTP服務器是能夠處理HTTP請求并返回響應的網絡服務程序。在物聯網應用中&#xff0c;ESP32可以作為輕量級HTTP服務器&#xff0c;直接接收來自客戶端(如瀏覽器、手機APP)的請求。 1.2 ESP32作為HTTP服務器的特點 輕量…

《棒球百科》MLB棒球公益課·棒球1號位

MLB&#xff08;美國職業棒球大聯盟&#xff09;的棒球公益課通過推廣棒球運動、普及體育教育&#xff0c;對全球多個地區產生了多層次的影響&#xff1a; 1. 體育文化推廣 非傳統棒球地區的普及&#xff1a;在棒球基礎較弱的地區&#xff08;如中國、歐洲部分國家&#xff09…

Baumer工業相機堡盟工業相機的工業視覺是否可以在室外可以做視覺檢測項目

Baumer工業相機堡盟工業相機的工業視覺是否可以在室外可以做視覺檢測項目 Baumer工業相機?視覺檢測項目為什么偏愛“室內環境”&#xff1f;?工業視覺中為什么傾向于室內環境**保障人員與設備安全**&#xff1a;室內環境可以提供更好的安全保障&#xff0c;避免檢測設備和人員…

1. 使用 IntelliJ IDEA 創建 React 項目:創建 React 項目界面詳解;配置 Yarn 為包管理器

1. 使用 IntelliJ IDEA 創建 React 項目&#xff1a;創建 React 項目界面詳解&#xff1b;配置 Yarn 為包管理器 &#x1f9e9; 使用 IntelliJ IDEA 創建 React 項目&#xff08;附 Yarn 配置與 Vite 建議&#xff09;&#x1f4f7; 創建 React 項目界面詳解1?? Name&#xf…

C++GO語言微服務之用戶信息處理②

目錄 01 03-獲取用戶信息-上 02 04-獲取用戶信息-下 03 05-更新用戶名實現 01 06-中間件簡介和中間件類型 02 07-中間件測試和模型分析 03 08-中間件測試案例和小結 04 09-項目使用中間件 01 03-獲取用戶信息-上 ## Cookie操作 ### 設置Cookie go func (c *Context) …

QMK鍵盤固件開發全解析:QMK 固件開發的最新架構和規范(2025最新版)

QMK鍵盤固件開發全解析:QMK 固件開發的最新架構和規范(2025最新版) ?? 前言概述 QMK(Quantum Mechanical Keyboard)作為目前開源鍵盤固件領域的"扛把子",憑借其強大的功能和活躍的社區支持,已經成為眾多DIY鍵盤愛好者的首選開發框架。無論是入門級玩家還是資…