@cj-tech-master/excelts 1.4.5-canary.20251212064440.3eb099f → 1.4.5-canary.20251212143538.45665af
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/excelts.iife.js +259 -20
- package/dist/browser/excelts.iife.js.map +1 -1
- package/dist/browser/excelts.iife.min.js +3 -3
- package/dist/cjs/doc/column.js +36 -7
- package/dist/cjs/doc/row.js +48 -18
- package/dist/cjs/doc/workbook.js +25 -2
- package/dist/cjs/doc/worksheet.js +153 -23
- package/dist/esm/doc/column.js +36 -7
- package/dist/esm/doc/row.js +48 -18
- package/dist/esm/doc/workbook.js +25 -2
- package/dist/esm/doc/worksheet.js +153 -23
- package/dist/types/doc/column.d.ts +37 -2
- package/dist/types/doc/row.d.ts +50 -5
- package/dist/types/doc/workbook.d.ts +24 -1
- package/dist/types/doc/worksheet.d.ts +158 -11
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @cj-tech-master/excelts v1.4.5-canary.
|
|
2
|
+
* @cj-tech-master/excelts v1.4.5-canary.20251212143538.45665af
|
|
3
3
|
* TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.
|
|
4
4
|
* (c) 2025 cjnoname
|
|
5
5
|
* Released under the MIT License
|
|
@@ -1559,15 +1559,29 @@ var ExcelTS = (function(exports) {
|
|
|
1559
1559
|
this.style = {};
|
|
1560
1560
|
this.outlineLevel = 0;
|
|
1561
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* The row number
|
|
1564
|
+
*/
|
|
1562
1565
|
get number() {
|
|
1563
1566
|
return this._number;
|
|
1564
1567
|
}
|
|
1568
|
+
/**
|
|
1569
|
+
* The worksheet that contains this row
|
|
1570
|
+
*/
|
|
1565
1571
|
get worksheet() {
|
|
1566
1572
|
return this._worksheet;
|
|
1567
1573
|
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Commit a completed row to stream.
|
|
1576
|
+
* Inform Streaming Writer that this row (and all rows before it) are complete
|
|
1577
|
+
* and ready to write. Has no effect on Worksheet document.
|
|
1578
|
+
*/
|
|
1568
1579
|
commit() {
|
|
1569
1580
|
this._worksheet._commitRow(this);
|
|
1570
1581
|
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Helps GC by breaking cyclic references
|
|
1584
|
+
*/
|
|
1571
1585
|
destroy() {
|
|
1572
1586
|
delete this._worksheet;
|
|
1573
1587
|
delete this._cells;
|
|
@@ -1585,6 +1599,9 @@ var ExcelTS = (function(exports) {
|
|
|
1585
1599
|
}
|
|
1586
1600
|
return cell;
|
|
1587
1601
|
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Get cell by number, column letter or column key
|
|
1604
|
+
*/
|
|
1588
1605
|
getCell(col) {
|
|
1589
1606
|
let colNum;
|
|
1590
1607
|
if (typeof col === "string") {
|
|
@@ -1598,6 +1615,11 @@ var ExcelTS = (function(exports) {
|
|
|
1598
1615
|
col: colNum
|
|
1599
1616
|
});
|
|
1600
1617
|
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Cut one or more cells (cells to the right are shifted left)
|
|
1620
|
+
*
|
|
1621
|
+
* Note: this operation will not affect other rows
|
|
1622
|
+
*/
|
|
1601
1623
|
splice(start, count, ...inserts) {
|
|
1602
1624
|
const nKeep = start + count;
|
|
1603
1625
|
const nExpand = inserts.length - count;
|
|
@@ -1635,19 +1657,19 @@ var ExcelTS = (function(exports) {
|
|
|
1635
1657
|
cDst.comment = void 0;
|
|
1636
1658
|
}
|
|
1637
1659
|
}
|
|
1638
|
-
eachCell(
|
|
1660
|
+
eachCell(optOrCallback, maybeCallback) {
|
|
1639
1661
|
let options = null;
|
|
1640
|
-
let
|
|
1641
|
-
if (typeof
|
|
1662
|
+
let callback;
|
|
1663
|
+
if (typeof optOrCallback === "function") callback = optOrCallback;
|
|
1642
1664
|
else {
|
|
1643
|
-
options =
|
|
1644
|
-
|
|
1665
|
+
options = optOrCallback;
|
|
1666
|
+
callback = maybeCallback;
|
|
1645
1667
|
}
|
|
1646
1668
|
if (options && options.includeEmpty) {
|
|
1647
1669
|
const n = this._cells.length;
|
|
1648
|
-
for (let i$1 = 1; i$1 <= n; i$1++)
|
|
1670
|
+
for (let i$1 = 1; i$1 <= n; i$1++) callback(this.getCell(i$1), i$1);
|
|
1649
1671
|
} else this._cells.forEach((cell, index) => {
|
|
1650
|
-
if (cell && cell.type !== Enums.ValueType.Null)
|
|
1672
|
+
if (cell && cell.type !== Enums.ValueType.Null) callback(cell, index + 1);
|
|
1651
1673
|
});
|
|
1652
1674
|
}
|
|
1653
1675
|
addPageBreak(lft, rght) {
|
|
@@ -1662,6 +1684,9 @@ var ExcelTS = (function(exports) {
|
|
|
1662
1684
|
if (left) pb.min = left;
|
|
1663
1685
|
ws.rowBreaks.push(pb);
|
|
1664
1686
|
}
|
|
1687
|
+
/**
|
|
1688
|
+
* Get a row as a sparse array
|
|
1689
|
+
*/
|
|
1665
1690
|
get values() {
|
|
1666
1691
|
const values = [];
|
|
1667
1692
|
this._cells.forEach((cell) => {
|
|
@@ -1669,6 +1694,9 @@ var ExcelTS = (function(exports) {
|
|
|
1669
1694
|
});
|
|
1670
1695
|
return values;
|
|
1671
1696
|
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Set the values by contiguous or sparse array, or by key'd object literal
|
|
1699
|
+
*/
|
|
1672
1700
|
set values(value) {
|
|
1673
1701
|
this._cells = [];
|
|
1674
1702
|
if (!value) {} else if (value instanceof Array) {
|
|
@@ -1689,12 +1717,21 @@ var ExcelTS = (function(exports) {
|
|
|
1689
1717
|
}).value = value[key];
|
|
1690
1718
|
});
|
|
1691
1719
|
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Returns true if the row includes at least one cell with a value
|
|
1722
|
+
*/
|
|
1692
1723
|
get hasValues() {
|
|
1693
1724
|
return this._cells.some((cell) => cell && cell.type !== Enums.ValueType.Null);
|
|
1694
1725
|
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Number of cells including empty ones
|
|
1728
|
+
*/
|
|
1695
1729
|
get cellCount() {
|
|
1696
1730
|
return this._cells.length;
|
|
1697
1731
|
}
|
|
1732
|
+
/**
|
|
1733
|
+
* Number of non-empty cells
|
|
1734
|
+
*/
|
|
1698
1735
|
get actualCellCount() {
|
|
1699
1736
|
let count = 0;
|
|
1700
1737
|
this.eachCell(() => {
|
|
@@ -1702,6 +1739,9 @@ var ExcelTS = (function(exports) {
|
|
|
1702
1739
|
});
|
|
1703
1740
|
return count;
|
|
1704
1741
|
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Get the min and max column number for the non-null cells in this row or null
|
|
1744
|
+
*/
|
|
1705
1745
|
get dimensions() {
|
|
1706
1746
|
let min = 0;
|
|
1707
1747
|
let max$1 = 0;
|
|
@@ -1837,6 +1877,11 @@ var ExcelTS = (function(exports) {
|
|
|
1837
1877
|
//#endregion
|
|
1838
1878
|
//#region src/doc/column.ts
|
|
1839
1879
|
const DEFAULT_COLUMN_WIDTH = 9;
|
|
1880
|
+
/**
|
|
1881
|
+
* Column defines the column properties for 1 column.
|
|
1882
|
+
* This includes header rows, widths, key, (style), etc.
|
|
1883
|
+
* Worksheet will condense the columns as appropriate during serialization
|
|
1884
|
+
*/
|
|
1840
1885
|
var Column = class Column {
|
|
1841
1886
|
constructor(worksheet, number, defn) {
|
|
1842
1887
|
this._worksheet = worksheet;
|
|
@@ -1849,6 +1894,9 @@ var ExcelTS = (function(exports) {
|
|
|
1849
1894
|
get worksheet() {
|
|
1850
1895
|
return this._worksheet;
|
|
1851
1896
|
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Column letter key
|
|
1899
|
+
*/
|
|
1852
1900
|
get letter() {
|
|
1853
1901
|
return colCache.n2l(this._number);
|
|
1854
1902
|
}
|
|
@@ -1887,6 +1935,9 @@ var ExcelTS = (function(exports) {
|
|
|
1887
1935
|
if (this._header !== void 0) return [this._header];
|
|
1888
1936
|
return [];
|
|
1889
1937
|
}
|
|
1938
|
+
/**
|
|
1939
|
+
* Can be a string to set one row high header or an array to set multi-row high header
|
|
1940
|
+
*/
|
|
1890
1941
|
get header() {
|
|
1891
1942
|
return this._header;
|
|
1892
1943
|
}
|
|
@@ -1898,6 +1949,9 @@ var ExcelTS = (function(exports) {
|
|
|
1898
1949
|
});
|
|
1899
1950
|
} else this._header = void 0;
|
|
1900
1951
|
}
|
|
1952
|
+
/**
|
|
1953
|
+
* The name of the properties associated with this column in each row
|
|
1954
|
+
*/
|
|
1901
1955
|
get key() {
|
|
1902
1956
|
return this._key;
|
|
1903
1957
|
}
|
|
@@ -1906,18 +1960,27 @@ var ExcelTS = (function(exports) {
|
|
|
1906
1960
|
this._key = value;
|
|
1907
1961
|
if (value) this._worksheet.setColumnKey(this._key, this);
|
|
1908
1962
|
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Hides the column
|
|
1965
|
+
*/
|
|
1909
1966
|
get hidden() {
|
|
1910
1967
|
return !!this._hidden;
|
|
1911
1968
|
}
|
|
1912
1969
|
set hidden(value) {
|
|
1913
1970
|
this._hidden = value;
|
|
1914
1971
|
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Set an outline level for columns
|
|
1974
|
+
*/
|
|
1915
1975
|
get outlineLevel() {
|
|
1916
1976
|
return this._outlineLevel || 0;
|
|
1917
1977
|
}
|
|
1918
1978
|
set outlineLevel(value) {
|
|
1919
1979
|
this._outlineLevel = value;
|
|
1920
1980
|
}
|
|
1981
|
+
/**
|
|
1982
|
+
* Indicate the collapsed state based on outlineLevel
|
|
1983
|
+
*/
|
|
1921
1984
|
get collapsed() {
|
|
1922
1985
|
return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol);
|
|
1923
1986
|
}
|
|
@@ -1945,16 +2008,24 @@ var ExcelTS = (function(exports) {
|
|
|
1945
2008
|
get headerCount() {
|
|
1946
2009
|
return this.headers.length;
|
|
1947
2010
|
}
|
|
1948
|
-
eachCell(
|
|
2011
|
+
eachCell(optionsOrCallback, maybeCallback) {
|
|
1949
2012
|
const colNumber = this.number;
|
|
1950
|
-
|
|
1951
|
-
|
|
2013
|
+
let options;
|
|
2014
|
+
let callback;
|
|
2015
|
+
if (typeof optionsOrCallback === "function") {
|
|
1952
2016
|
options = {};
|
|
2017
|
+
callback = optionsOrCallback;
|
|
2018
|
+
} else {
|
|
2019
|
+
options = optionsOrCallback;
|
|
2020
|
+
callback = maybeCallback;
|
|
1953
2021
|
}
|
|
1954
2022
|
this._worksheet.eachRow(options, (row, rowNumber) => {
|
|
1955
|
-
|
|
2023
|
+
callback(row.getCell(colNumber), rowNumber);
|
|
1956
2024
|
});
|
|
1957
2025
|
}
|
|
2026
|
+
/**
|
|
2027
|
+
* The cell values in the column
|
|
2028
|
+
*/
|
|
1958
2029
|
get values() {
|
|
1959
2030
|
const v = [];
|
|
1960
2031
|
this.eachCell((cell, rowNumber) => {
|
|
@@ -26576,12 +26647,21 @@ var ExcelTS = (function(exports) {
|
|
|
26576
26647
|
if (this._workbook.worksheets.find((ws) => ws && ws.name.toLowerCase() === name.toLowerCase())) throw new Error(`Worksheet name already exists: ${name}`);
|
|
26577
26648
|
this._name = name;
|
|
26578
26649
|
}
|
|
26650
|
+
/**
|
|
26651
|
+
* The workbook that contains this worksheet
|
|
26652
|
+
*/
|
|
26579
26653
|
get workbook() {
|
|
26580
26654
|
return this._workbook;
|
|
26581
26655
|
}
|
|
26656
|
+
/**
|
|
26657
|
+
* When you're done with this worksheet, call this to remove from workbook
|
|
26658
|
+
*/
|
|
26582
26659
|
destroy() {
|
|
26583
26660
|
this._workbook.removeWorksheetEx(this);
|
|
26584
26661
|
}
|
|
26662
|
+
/**
|
|
26663
|
+
* Get the bounding range of the cells in this worksheet
|
|
26664
|
+
*/
|
|
26585
26665
|
get dimensions() {
|
|
26586
26666
|
const dimensions = new Range();
|
|
26587
26667
|
this._rows.forEach((row) => {
|
|
@@ -26592,9 +26672,18 @@ var ExcelTS = (function(exports) {
|
|
|
26592
26672
|
});
|
|
26593
26673
|
return dimensions;
|
|
26594
26674
|
}
|
|
26675
|
+
/**
|
|
26676
|
+
* Get the current columns array
|
|
26677
|
+
*/
|
|
26595
26678
|
get columns() {
|
|
26596
26679
|
return this._columns;
|
|
26597
26680
|
}
|
|
26681
|
+
/**
|
|
26682
|
+
* Add column headers and define column keys and widths.
|
|
26683
|
+
*
|
|
26684
|
+
* Note: these column structures are a workbook-building convenience only,
|
|
26685
|
+
* apart from the column width, they will not be fully persisted.
|
|
26686
|
+
*/
|
|
26598
26687
|
set columns(value) {
|
|
26599
26688
|
this._headerRowCount = value.reduce((pv, cv) => {
|
|
26600
26689
|
const headerCount = Array.isArray(cv.header) ? cv.header.length : cv.header ? 1 : 0;
|
|
@@ -26620,6 +26709,9 @@ var ExcelTS = (function(exports) {
|
|
|
26620
26709
|
eachColumnKey(f) {
|
|
26621
26710
|
Object.keys(this._keys).forEach((key) => f(this._keys[key], key));
|
|
26622
26711
|
}
|
|
26712
|
+
/**
|
|
26713
|
+
* Access an individual column by key, letter and 1-based column number
|
|
26714
|
+
*/
|
|
26623
26715
|
getColumn(c) {
|
|
26624
26716
|
let colNum;
|
|
26625
26717
|
if (typeof c === "string") {
|
|
@@ -26634,6 +26726,17 @@ var ExcelTS = (function(exports) {
|
|
|
26634
26726
|
}
|
|
26635
26727
|
return this._columns[colNum - 1];
|
|
26636
26728
|
}
|
|
26729
|
+
/**
|
|
26730
|
+
* Cut one or more columns (columns to the right are shifted left)
|
|
26731
|
+
* and optionally insert more
|
|
26732
|
+
*
|
|
26733
|
+
* If column properties have been defined, they will be cut or moved accordingly
|
|
26734
|
+
*
|
|
26735
|
+
* Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
|
|
26736
|
+
*
|
|
26737
|
+
* Also: If the worksheet has more rows than values in the column inserts,
|
|
26738
|
+
* the rows will still be shifted as if the values existed
|
|
26739
|
+
*/
|
|
26637
26740
|
spliceColumns(start, count, ...inserts) {
|
|
26638
26741
|
const nRows = this._rows.length;
|
|
26639
26742
|
if (inserts.length > 0) for (let i$1 = 0; i$1 < nRows; i$1++) {
|
|
@@ -26651,9 +26754,15 @@ var ExcelTS = (function(exports) {
|
|
|
26651
26754
|
for (let i$1 = start; i$1 < start + inserts.length; i$1++) this.getColumn(i$1).defn = void 0;
|
|
26652
26755
|
this.workbook.definedNames.spliceColumns(this.name, start, count, inserts.length);
|
|
26653
26756
|
}
|
|
26757
|
+
/**
|
|
26758
|
+
* Get the last column in a worksheet
|
|
26759
|
+
*/
|
|
26654
26760
|
get lastColumn() {
|
|
26655
26761
|
return this.getColumn(this.columnCount);
|
|
26656
26762
|
}
|
|
26763
|
+
/**
|
|
26764
|
+
* The total column size of the document. Equal to the maximum cell count from all of the rows
|
|
26765
|
+
*/
|
|
26657
26766
|
get columnCount() {
|
|
26658
26767
|
let maxCount = 0;
|
|
26659
26768
|
this.eachRow((row) => {
|
|
@@ -26661,6 +26770,9 @@ var ExcelTS = (function(exports) {
|
|
|
26661
26770
|
});
|
|
26662
26771
|
return maxCount;
|
|
26663
26772
|
}
|
|
26773
|
+
/**
|
|
26774
|
+
* A count of the number of columns that have values
|
|
26775
|
+
*/
|
|
26664
26776
|
get actualColumnCount() {
|
|
26665
26777
|
const counts = [];
|
|
26666
26778
|
let count = 0;
|
|
@@ -26684,18 +26796,38 @@ var ExcelTS = (function(exports) {
|
|
|
26684
26796
|
get _nextRow() {
|
|
26685
26797
|
return this._lastRowNumber + 1;
|
|
26686
26798
|
}
|
|
26799
|
+
/**
|
|
26800
|
+
* Get the last editable row in a worksheet (or undefined if there are none)
|
|
26801
|
+
*/
|
|
26687
26802
|
get lastRow() {
|
|
26688
26803
|
if (this._rows.length) return this._rows[this._rows.length - 1];
|
|
26689
26804
|
}
|
|
26805
|
+
/**
|
|
26806
|
+
* Tries to find and return row for row number, else undefined
|
|
26807
|
+
*
|
|
26808
|
+
* @param r - The 1-indexed row number
|
|
26809
|
+
*/
|
|
26690
26810
|
findRow(r) {
|
|
26691
26811
|
return this._rows[r - 1];
|
|
26692
26812
|
}
|
|
26813
|
+
/**
|
|
26814
|
+
* Tries to find and return rows for row number start and length, else undefined
|
|
26815
|
+
*
|
|
26816
|
+
* @param start - The 1-indexed starting row number
|
|
26817
|
+
* @param length - The length of the expected array
|
|
26818
|
+
*/
|
|
26693
26819
|
findRows(start, length) {
|
|
26694
26820
|
return this._rows.slice(start - 1, start - 1 + length);
|
|
26695
26821
|
}
|
|
26822
|
+
/**
|
|
26823
|
+
* The total row size of the document. Equal to the row number of the last row that has values.
|
|
26824
|
+
*/
|
|
26696
26825
|
get rowCount() {
|
|
26697
26826
|
return this._lastRowNumber;
|
|
26698
26827
|
}
|
|
26828
|
+
/**
|
|
26829
|
+
* A count of the number of rows that have values. If a mid-document row is empty, it will not be included in the count.
|
|
26830
|
+
*/
|
|
26699
26831
|
get actualRowCount() {
|
|
26700
26832
|
let count = 0;
|
|
26701
26833
|
this.eachRow(() => {
|
|
@@ -26703,17 +26835,27 @@ var ExcelTS = (function(exports) {
|
|
|
26703
26835
|
});
|
|
26704
26836
|
return count;
|
|
26705
26837
|
}
|
|
26838
|
+
/**
|
|
26839
|
+
* Get or create row by 1-based index
|
|
26840
|
+
*/
|
|
26706
26841
|
getRow(r) {
|
|
26707
26842
|
let row = this._rows[r - 1];
|
|
26708
26843
|
if (!row) row = this._rows[r - 1] = new Row(this, r);
|
|
26709
26844
|
return row;
|
|
26710
26845
|
}
|
|
26846
|
+
/**
|
|
26847
|
+
* Get or create rows by 1-based index
|
|
26848
|
+
*/
|
|
26711
26849
|
getRows(start, length) {
|
|
26712
26850
|
if (length < 1) return;
|
|
26713
26851
|
const rows = [];
|
|
26714
26852
|
for (let i$1 = start; i$1 < start + length; i$1++) rows.push(this.getRow(i$1));
|
|
26715
26853
|
return rows;
|
|
26716
26854
|
}
|
|
26855
|
+
/**
|
|
26856
|
+
* Add a couple of Rows by key-value, after the last current row, using the column keys,
|
|
26857
|
+
* or add a row by contiguous Array (assign to columns A, B & C)
|
|
26858
|
+
*/
|
|
26717
26859
|
addRow(value, style = "n") {
|
|
26718
26860
|
const rowNo = this._nextRow;
|
|
26719
26861
|
const row = this.getRow(rowNo);
|
|
@@ -26721,6 +26863,9 @@ var ExcelTS = (function(exports) {
|
|
|
26721
26863
|
this._setStyleOption(rowNo, style[0] === "i" ? style : "n");
|
|
26722
26864
|
return row;
|
|
26723
26865
|
}
|
|
26866
|
+
/**
|
|
26867
|
+
* Add multiple rows by providing an array of arrays or key-value pairs
|
|
26868
|
+
*/
|
|
26724
26869
|
addRows(value, style = "n") {
|
|
26725
26870
|
const rows = [];
|
|
26726
26871
|
value.forEach((row) => {
|
|
@@ -26728,11 +26873,19 @@ var ExcelTS = (function(exports) {
|
|
|
26728
26873
|
});
|
|
26729
26874
|
return rows;
|
|
26730
26875
|
}
|
|
26876
|
+
/**
|
|
26877
|
+
* Insert a Row by key-value, at the position (shifting down all rows from position),
|
|
26878
|
+
* using the column keys, or add a row by contiguous Array (assign to columns A, B & C)
|
|
26879
|
+
*/
|
|
26731
26880
|
insertRow(pos, value, style = "n") {
|
|
26732
26881
|
this.spliceRows(pos, 0, value);
|
|
26733
26882
|
this._setStyleOption(pos, style);
|
|
26734
26883
|
return this.getRow(pos);
|
|
26735
26884
|
}
|
|
26885
|
+
/**
|
|
26886
|
+
* Insert multiple rows at position (shifting down all rows from position)
|
|
26887
|
+
* by providing an array of arrays or key-value pairs
|
|
26888
|
+
*/
|
|
26736
26889
|
insertRows(pos, values, style = "n") {
|
|
26737
26890
|
this.spliceRows(pos, 0, ...values);
|
|
26738
26891
|
if (style !== "n") {
|
|
@@ -26754,6 +26907,9 @@ var ExcelTS = (function(exports) {
|
|
|
26754
26907
|
});
|
|
26755
26908
|
rDst.height = rSrc.height;
|
|
26756
26909
|
}
|
|
26910
|
+
/**
|
|
26911
|
+
* Duplicate rows and insert new rows
|
|
26912
|
+
*/
|
|
26757
26913
|
duplicateRow(rowNum, count, insert = false) {
|
|
26758
26914
|
const rSrc = this._rows[rowNum - 1];
|
|
26759
26915
|
const inserts = Array.from({ length: count }).fill(rSrc.values);
|
|
@@ -26767,6 +26923,12 @@ var ExcelTS = (function(exports) {
|
|
|
26767
26923
|
});
|
|
26768
26924
|
}
|
|
26769
26925
|
}
|
|
26926
|
+
/**
|
|
26927
|
+
* Cut one or more rows (rows below are shifted up)
|
|
26928
|
+
* and optionally insert more
|
|
26929
|
+
*
|
|
26930
|
+
* Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
|
|
26931
|
+
*/
|
|
26770
26932
|
spliceRows(start, count, ...inserts) {
|
|
26771
26933
|
const nKeep = start + count;
|
|
26772
26934
|
const nInserts = inserts.length;
|
|
@@ -26814,18 +26976,24 @@ var ExcelTS = (function(exports) {
|
|
|
26814
26976
|
}
|
|
26815
26977
|
this.workbook.definedNames.spliceRows(this.name, start, count, nInserts);
|
|
26816
26978
|
}
|
|
26817
|
-
eachRow(
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26979
|
+
eachRow(optOrCallback, maybeCallback) {
|
|
26980
|
+
let options;
|
|
26981
|
+
let callback;
|
|
26982
|
+
if (typeof optOrCallback === "function") callback = optOrCallback;
|
|
26983
|
+
else {
|
|
26984
|
+
options = optOrCallback;
|
|
26985
|
+
callback = maybeCallback;
|
|
26821
26986
|
}
|
|
26822
26987
|
if (options && options.includeEmpty) {
|
|
26823
26988
|
const n = this._rows.length;
|
|
26824
|
-
for (let i$1 = 1; i$1 <= n; i$1++)
|
|
26989
|
+
for (let i$1 = 1; i$1 <= n; i$1++) callback(this.getRow(i$1), i$1);
|
|
26825
26990
|
} else this._rows.forEach((row) => {
|
|
26826
|
-
if (row && row.hasValues)
|
|
26991
|
+
if (row && row.hasValues) callback(row, row.number);
|
|
26827
26992
|
});
|
|
26828
26993
|
}
|
|
26994
|
+
/**
|
|
26995
|
+
* Return all rows as sparse array
|
|
26996
|
+
*/
|
|
26829
26997
|
getSheetValues() {
|
|
26830
26998
|
const rows = [];
|
|
26831
26999
|
this._rows.forEach((row) => {
|
|
@@ -26833,15 +27001,30 @@ var ExcelTS = (function(exports) {
|
|
|
26833
27001
|
});
|
|
26834
27002
|
return rows;
|
|
26835
27003
|
}
|
|
27004
|
+
/**
|
|
27005
|
+
* Returns the cell at [r,c] or address given by r. If not found, return undefined
|
|
27006
|
+
*/
|
|
26836
27007
|
findCell(r, c) {
|
|
26837
27008
|
const address = colCache.getAddress(r, c);
|
|
26838
27009
|
const row = this._rows[address.row - 1];
|
|
26839
27010
|
return row ? row.findCell(address.col) : void 0;
|
|
26840
27011
|
}
|
|
27012
|
+
/**
|
|
27013
|
+
* Get or create cell at [r,c] or address given by r
|
|
27014
|
+
*/
|
|
26841
27015
|
getCell(r, c) {
|
|
26842
27016
|
const address = colCache.getAddress(r, c);
|
|
26843
27017
|
return this.getRow(address.row).getCellEx(address);
|
|
26844
27018
|
}
|
|
27019
|
+
/**
|
|
27020
|
+
* Merge cells, either:
|
|
27021
|
+
*
|
|
27022
|
+
* tlbr string, e.g. `'A4:B5'`
|
|
27023
|
+
*
|
|
27024
|
+
* tl string, br string, e.g. `'G10', 'H11'`
|
|
27025
|
+
*
|
|
27026
|
+
* t, l, b, r numbers, e.g. `10,11,12,13`
|
|
27027
|
+
*/
|
|
26845
27028
|
mergeCells(...cells) {
|
|
26846
27029
|
const dimensions = new Range(cells);
|
|
26847
27030
|
this._mergeCellsInternal(dimensions);
|
|
@@ -26868,6 +27051,11 @@ var ExcelTS = (function(exports) {
|
|
|
26868
27051
|
get hasMerges() {
|
|
26869
27052
|
return Object.values(this._merges).some(Boolean);
|
|
26870
27053
|
}
|
|
27054
|
+
/**
|
|
27055
|
+
* Scan the range and if any cell is part of a merge, un-merge the group.
|
|
27056
|
+
* Note this function can affect multiple merges and merge-blocks are
|
|
27057
|
+
* atomic - either they're all merged or all un-merged.
|
|
27058
|
+
*/
|
|
26871
27059
|
unMergeCells(...cells) {
|
|
26872
27060
|
const dimensions = new Range(cells);
|
|
26873
27061
|
for (let i$1 = dimensions.top; i$1 <= dimensions.bottom; i$1++) for (let j = dimensions.left; j <= dimensions.right; j++) {
|
|
@@ -26903,6 +27091,10 @@ var ExcelTS = (function(exports) {
|
|
|
26903
27091
|
result: getResult(r, c)
|
|
26904
27092
|
} : getResult(r, c);
|
|
26905
27093
|
}
|
|
27094
|
+
/**
|
|
27095
|
+
* Using the image id from `Workbook.addImage`,
|
|
27096
|
+
* embed an image within the worksheet to cover a range
|
|
27097
|
+
*/
|
|
26906
27098
|
addImage(imageId, range$1) {
|
|
26907
27099
|
const model = {
|
|
26908
27100
|
type: "image",
|
|
@@ -26914,6 +27106,9 @@ var ExcelTS = (function(exports) {
|
|
|
26914
27106
|
getImages() {
|
|
26915
27107
|
return this._media.filter((m) => m.type === "image");
|
|
26916
27108
|
}
|
|
27109
|
+
/**
|
|
27110
|
+
* Using the image id from `Workbook.addImage`, set the background to the worksheet
|
|
27111
|
+
*/
|
|
26917
27112
|
addBackgroundImage(imageId) {
|
|
26918
27113
|
const model = {
|
|
26919
27114
|
type: "background",
|
|
@@ -26925,6 +27120,9 @@ var ExcelTS = (function(exports) {
|
|
|
26925
27120
|
const image = this._media.find((m) => m.type === "background");
|
|
26926
27121
|
return image && image.imageId;
|
|
26927
27122
|
}
|
|
27123
|
+
/**
|
|
27124
|
+
* Protect the worksheet with optional password and options
|
|
27125
|
+
*/
|
|
26928
27126
|
protect(password, options) {
|
|
26929
27127
|
return new Promise((resolve) => {
|
|
26930
27128
|
this.sheetProtection = { sheet: true };
|
|
@@ -26945,17 +27143,29 @@ var ExcelTS = (function(exports) {
|
|
|
26945
27143
|
unprotect() {
|
|
26946
27144
|
this.sheetProtection = null;
|
|
26947
27145
|
}
|
|
27146
|
+
/**
|
|
27147
|
+
* Add a new table and return a reference to it
|
|
27148
|
+
*/
|
|
26948
27149
|
addTable(model) {
|
|
26949
27150
|
const table = new Table(this, model);
|
|
26950
27151
|
this.tables[model.name] = table;
|
|
26951
27152
|
return table;
|
|
26952
27153
|
}
|
|
27154
|
+
/**
|
|
27155
|
+
* Fetch table by name
|
|
27156
|
+
*/
|
|
26953
27157
|
getTable(name) {
|
|
26954
27158
|
return this.tables[name];
|
|
26955
27159
|
}
|
|
27160
|
+
/**
|
|
27161
|
+
* Delete table by name
|
|
27162
|
+
*/
|
|
26956
27163
|
removeTable(name) {
|
|
26957
27164
|
delete this.tables[name];
|
|
26958
27165
|
}
|
|
27166
|
+
/**
|
|
27167
|
+
* Fetch all tables in the worksheet
|
|
27168
|
+
*/
|
|
26959
27169
|
getTables() {
|
|
26960
27170
|
return Object.values(this.tables);
|
|
26961
27171
|
}
|
|
@@ -26967,9 +27177,15 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
|
|
|
26967
27177
|
this.workbook.pivotTables.push(pivotTable);
|
|
26968
27178
|
return pivotTable;
|
|
26969
27179
|
}
|
|
27180
|
+
/**
|
|
27181
|
+
* Add conditional formatting rules
|
|
27182
|
+
*/
|
|
26970
27183
|
addConditionalFormatting(cf) {
|
|
26971
27184
|
this.conditionalFormattings.push(cf);
|
|
26972
27185
|
}
|
|
27186
|
+
/**
|
|
27187
|
+
* Delete conditional formatting rules
|
|
27188
|
+
*/
|
|
26973
27189
|
removeConditionalFormatting(filter) {
|
|
26974
27190
|
if (typeof filter === "number") this.conditionalFormattings.splice(filter, 1);
|
|
26975
27191
|
else if (filter instanceof Function) this.conditionalFormattings = this.conditionalFormattings.filter(filter);
|
|
@@ -50309,10 +50525,16 @@ ${XMLNS_NAMESPACE}.`);
|
|
|
50309
50525
|
this.pivotTables = [];
|
|
50310
50526
|
this._definedNames = new DefinedNames();
|
|
50311
50527
|
}
|
|
50528
|
+
/**
|
|
50529
|
+
* xlsx file format operations
|
|
50530
|
+
*/
|
|
50312
50531
|
get xlsx() {
|
|
50313
50532
|
if (!this._xlsx) this._xlsx = new XLSX(this);
|
|
50314
50533
|
return this._xlsx;
|
|
50315
50534
|
}
|
|
50535
|
+
/**
|
|
50536
|
+
* csv file format operations
|
|
50537
|
+
*/
|
|
50316
50538
|
get csv() {
|
|
50317
50539
|
if (!this._csv) this._csv = new CSV(this);
|
|
50318
50540
|
return this._csv;
|
|
@@ -50321,6 +50543,9 @@ ${XMLNS_NAMESPACE}.`);
|
|
|
50321
50543
|
for (let i$1 = 1; i$1 < this._worksheets.length; i$1++) if (!this._worksheets[i$1]) return i$1;
|
|
50322
50544
|
return this._worksheets.length || 1;
|
|
50323
50545
|
}
|
|
50546
|
+
/**
|
|
50547
|
+
* Add a new worksheet and return a reference to it
|
|
50548
|
+
*/
|
|
50324
50549
|
addWorksheet(name, options) {
|
|
50325
50550
|
const id = this.nextId;
|
|
50326
50551
|
const lastOrderNo = this._worksheets.reduce((acc, ws) => (ws && ws.orderNo) > acc ? ws.orderNo : acc, 0);
|
|
@@ -50341,17 +50566,28 @@ ${XMLNS_NAMESPACE}.`);
|
|
|
50341
50566
|
const worksheet = this.getWorksheet(id);
|
|
50342
50567
|
if (worksheet) worksheet.destroy();
|
|
50343
50568
|
}
|
|
50569
|
+
/**
|
|
50570
|
+
* Fetch sheet by name or id
|
|
50571
|
+
*/
|
|
50344
50572
|
getWorksheet(id) {
|
|
50345
50573
|
if (id === void 0) return this._worksheets.find(Boolean);
|
|
50346
50574
|
if (typeof id === "number") return this._worksheets[id];
|
|
50347
50575
|
if (typeof id === "string") return this._worksheets.find((worksheet) => worksheet && worksheet.name === id);
|
|
50348
50576
|
}
|
|
50577
|
+
/**
|
|
50578
|
+
* Return a clone of worksheets in order
|
|
50579
|
+
*/
|
|
50349
50580
|
get worksheets() {
|
|
50350
50581
|
return this._worksheets.slice(1).sort((a, b) => a.orderNo - b.orderNo).filter(Boolean);
|
|
50351
50582
|
}
|
|
50352
|
-
|
|
50583
|
+
/**
|
|
50584
|
+
* Iterate over all sheets.
|
|
50585
|
+
*
|
|
50586
|
+
* Note: `workbook.worksheets.forEach` will still work but this is better.
|
|
50587
|
+
*/
|
|
50588
|
+
eachSheet(callback) {
|
|
50353
50589
|
this.worksheets.forEach((sheet) => {
|
|
50354
|
-
|
|
50590
|
+
callback(sheet, sheet.id);
|
|
50355
50591
|
});
|
|
50356
50592
|
}
|
|
50357
50593
|
get definedNames() {
|
|
@@ -50360,6 +50596,9 @@ ${XMLNS_NAMESPACE}.`);
|
|
|
50360
50596
|
clearThemes() {
|
|
50361
50597
|
this._themes = void 0;
|
|
50362
50598
|
}
|
|
50599
|
+
/**
|
|
50600
|
+
* Add Image to Workbook and return the id
|
|
50601
|
+
*/
|
|
50363
50602
|
addImage(image) {
|
|
50364
50603
|
const id = this.media.length;
|
|
50365
50604
|
this.media.push({
|