|
|
@@ -1,18 +1,18 @@
|
|
|
"use strict";
|
|
|
|
|
|
// const _ = require("lodash");
|
|
|
-const cloneDeep = require("lodash/cloneDeep");
|
|
|
-const filter = require("lodash/filter");
|
|
|
-const findIndex = require("lodash/findIndex");
|
|
|
-const forEach = require("lodash/forEach");
|
|
|
-const clone = require("lodash/clone");
|
|
|
-const values = require("lodash/values");
|
|
|
-const assign = require("lodash/assign");
|
|
|
-const isEqual = require("lodash/isEqual");
|
|
|
-const sortBy = require("lodash/sortBy");
|
|
|
-const isNaN = require("lodash/isNaN");
|
|
|
-const includes = require("lodash/includes");
|
|
|
-const isNumber = require("lodash/isNumber");
|
|
|
+const _cloneDeep = require("lodash/cloneDeep");
|
|
|
+const _filter = require("lodash/filter");
|
|
|
+const _findIndex = require("lodash/findIndex");
|
|
|
+const _forEach = require("lodash/forEach");
|
|
|
+const _clone = require("lodash/clone");
|
|
|
+const _values = require("lodash/values");
|
|
|
+const _assign = require("lodash/assign");
|
|
|
+const _isEqual = require("lodash/isEqual");
|
|
|
+const _sortBy = require("lodash/sortBy");
|
|
|
+const _isNaN = require("lodash/isNaN");
|
|
|
+const _includes = require("lodash/includes");
|
|
|
+const _isNumber = require("lodash/isNumber");
|
|
|
|
|
|
const Cell = require("./Cell");
|
|
|
const Row = require("./Row");
|
|
|
@@ -162,7 +162,7 @@ class Sheet {
|
|
|
// If the existing node covered earlier columns than the new one, we need to have a col node to cover the min up to our new node.
|
|
|
if (existingColNode.attributes.min < columnNumber) {
|
|
|
// Clone the node and set the max to the column before our new col.
|
|
|
- const beforeColNode = cloneDeep(existingColNode);
|
|
|
+ const beforeColNode = _cloneDeep(existingColNode);
|
|
|
beforeColNode.attributes.max = columnNumber - 1;
|
|
|
|
|
|
// Update the col nodes cache.
|
|
|
@@ -172,14 +172,14 @@ class Sheet {
|
|
|
}
|
|
|
|
|
|
// Make a clone for the new column. Set the min/max to the column number and cache it.
|
|
|
- colNode = cloneDeep(existingColNode);
|
|
|
+ colNode = _cloneDeep(existingColNode);
|
|
|
colNode.attributes.min = columnNumber;
|
|
|
colNode.attributes.max = columnNumber;
|
|
|
this._colNodes[columnNumber] = colNode;
|
|
|
|
|
|
// If the max of the existing node is greater than the nre one, create a col node for that too.
|
|
|
if (existingColNode.attributes.max > columnNumber) {
|
|
|
- const afterColNode = cloneDeep(existingColNode);
|
|
|
+ const afterColNode = _cloneDeep(existingColNode);
|
|
|
afterColNode.attributes.min = columnNumber + 1;
|
|
|
for (let i = afterColNode.attributes.min; i <= afterColNode.attributes.max; i++) {
|
|
|
this._colNodes[i] = afterColNode;
|
|
|
@@ -292,7 +292,7 @@ class Sheet {
|
|
|
})
|
|
|
.case('*', hidden => {
|
|
|
if (hidden) {
|
|
|
- const visibleSheets = filter(this.workbook().sheets(), sheet => !sheet.hidden());
|
|
|
+ const visibleSheets = _filter(this.workbook().sheets(), sheet => !sheet.hidden());
|
|
|
if (visibleSheets.length === 1 && visibleSheets[0] === this) {
|
|
|
throw new Error("This sheet may not be hidden as a workbook must contain at least one visible sheet.");
|
|
|
}
|
|
|
@@ -483,7 +483,7 @@ class Sheet {
|
|
|
* @returns {Range|undefined} The used range or undefined if no cells in the sheet are used.
|
|
|
*/
|
|
|
usedRange() {
|
|
|
- const minRowNumber = findIndex(this._rows);
|
|
|
+ const minRowNumber = _findIndex(this._rows);
|
|
|
const maxRowNumber = this._rows.length - 1;
|
|
|
|
|
|
let minColumnNumber = 0;
|
|
|
@@ -570,7 +570,7 @@ class Sheet {
|
|
|
* @ignore
|
|
|
*/
|
|
|
forEachExistingColumnNumber(callback) {
|
|
|
- forEach(this._colNodes, (node, columnNumber) => {
|
|
|
+ _forEach(this._colNodes, (node, columnNumber) => {
|
|
|
if (!node) return;
|
|
|
callback(columnNumber);
|
|
|
});
|
|
|
@@ -583,7 +583,7 @@ class Sheet {
|
|
|
* @ignore
|
|
|
*/
|
|
|
forEachExistingRow(callback) {
|
|
|
- forEach(this._rows, (row, rowNumber) => {
|
|
|
+ _forEach(this._rows, (row, rowNumber) => {
|
|
|
if (row) callback(row, rowNumber);
|
|
|
});
|
|
|
|
|
|
@@ -841,11 +841,11 @@ class Sheet {
|
|
|
*/
|
|
|
toXmls() {
|
|
|
// Shallow clone the node so we don't have to remove these children later if they don't belong.
|
|
|
- const node = clone(this._node);
|
|
|
+ const node = _clone(this._node);
|
|
|
node.children = node.children.slice();
|
|
|
|
|
|
// Add the columns if needed.
|
|
|
- this._colsNode.children = filter(this._colNodes, (colNode, i) => {
|
|
|
+ this._colsNode.children = _filter(this._colNodes, (colNode, i) => {
|
|
|
// Columns should only be present if they have attributes other than min/max.
|
|
|
return colNode && i === colNode.attributes.min && Object.keys(colNode.attributes).length > 2;
|
|
|
});
|
|
|
@@ -854,7 +854,7 @@ class Sheet {
|
|
|
}
|
|
|
|
|
|
// Add the hyperlinks if needed.
|
|
|
- this._hyperlinksNode.children = values(this._hyperlinks);
|
|
|
+ this._hyperlinksNode.children = _values(this._hyperlinks);
|
|
|
if (this._hyperlinksNode.children.length) {
|
|
|
xmlq.insertInOrder(node, this._hyperlinksNode, nodeOrder);
|
|
|
}
|
|
|
@@ -869,10 +869,10 @@ class Sheet {
|
|
|
// Add the pageMargins if needed.
|
|
|
if (this._pageMarginsNode && this._pageMarginsPresetName) {
|
|
|
// Clone to preserve the current state of this sheet.
|
|
|
- const childNode = clone(this._pageMarginsNode);
|
|
|
+ const childNode = _clone(this._pageMarginsNode);
|
|
|
if (Object.keys(this._pageMarginsNode.attributes).length) {
|
|
|
// Fill in any missing attribute values with presets.
|
|
|
- childNode.attributes = assign(
|
|
|
+ childNode.attributes = _assign(
|
|
|
this._pageMarginsPresets[this._pageMarginsPresetName],
|
|
|
this._pageMarginsNode.attributes);
|
|
|
} else {
|
|
|
@@ -883,13 +883,13 @@ class Sheet {
|
|
|
}
|
|
|
|
|
|
// Add the merge cells if needed.
|
|
|
- this._mergeCellsNode.children = values(this._mergeCells);
|
|
|
+ this._mergeCellsNode.children = _values(this._mergeCells);
|
|
|
if (this._mergeCellsNode.children.length) {
|
|
|
xmlq.insertInOrder(node, this._mergeCellsNode, nodeOrder);
|
|
|
}
|
|
|
|
|
|
// Add the DataValidation cells if needed.
|
|
|
- this._dataValidationsNode.children = values(this._dataValidations);
|
|
|
+ this._dataValidationsNode.children = _values(this._dataValidations);
|
|
|
if (this._dataValidationsNode.children.length) {
|
|
|
xmlq.insertInOrder(node, this._dataValidationsNode, nodeOrder);
|
|
|
}
|
|
|
@@ -1104,17 +1104,17 @@ class Sheet {
|
|
|
// Validate preset attribute keys.
|
|
|
const pageMarginsAttributeNames = [
|
|
|
'left', 'right', 'top', 'bottom', 'header', 'footer'];
|
|
|
- const isValidPresetAttributeKeys = isEqual(
|
|
|
- sortBy(pageMarginsAttributeNames),
|
|
|
- sortBy(Object.keys(presetAttributes)));
|
|
|
+ const isValidPresetAttributeKeys = _isEqual(
|
|
|
+ _sortBy(pageMarginsAttributeNames),
|
|
|
+ _sortBy(Object.keys(presetAttributes)));
|
|
|
if (isValidPresetAttributeKeys === false) {
|
|
|
throw new Error(`Sheet.pageMarginsPreset: Invalid preset attributes for one or key(s)! - "${Object.keys(presetAttributes)}"`);
|
|
|
}
|
|
|
|
|
|
// Validate preset attribute values.
|
|
|
- forEach((attributeValue, attributeName) => {
|
|
|
+ _forEach((attributeValue, attributeName) => {
|
|
|
const attributeNumberValue = parseFloat(attributeValue);
|
|
|
- if (isNaN(attributeNumberValue) || isNumber(attributeNumberValue) === false) {
|
|
|
+ if (_isNaN(attributeNumberValue) || _isNumber(attributeNumberValue) === false) {
|
|
|
throw new Error(`Sheet.pageMarginsPreset: Invalid preset attribute value! - "${attributeValue}"`);
|
|
|
}
|
|
|
});
|
|
|
@@ -1162,7 +1162,7 @@ class Sheet {
|
|
|
return new ArgHandler('Sheet.pane')
|
|
|
.case(() => {
|
|
|
if (paneNode) {
|
|
|
- const result = cloneDeep(paneNode.attributes);
|
|
|
+ const result = _cloneDeep(paneNode.attributes);
|
|
|
if (!result.state) result.state = 'split';
|
|
|
return result;
|
|
|
}
|
|
|
@@ -1172,7 +1172,7 @@ class Sheet {
|
|
|
return this;
|
|
|
})
|
|
|
.case(['object'], paneAttributes => {
|
|
|
- const attributes = assign({ activePane: 'bottomRight' }, paneAttributes);
|
|
|
+ const attributes = _assign({ activePane: 'bottomRight' }, paneAttributes);
|
|
|
checkStateName(attributes.state);
|
|
|
checkActivePane(attributes.activePane);
|
|
|
if (paneNode) {
|
|
|
@@ -1250,7 +1250,7 @@ class Sheet {
|
|
|
*/
|
|
|
_getCheckAttributeNameHelper(functionName, supportedAttributeNames) {
|
|
|
return attributeName => {
|
|
|
- if (!includes(supportedAttributeNames, attributeName)) {
|
|
|
+ if (!_includes(supportedAttributeNames, attributeName)) {
|
|
|
throw new Error(`Sheet.${functionName}: "${attributeName}" is not supported.`);
|
|
|
}
|
|
|
};
|
|
|
@@ -1385,7 +1385,7 @@ class Sheet {
|
|
|
|
|
|
// Cache the col nodes.
|
|
|
this._colNodes = [];
|
|
|
- forEach(this._colsNode.children, colNode => {
|
|
|
+ _forEach(this._colsNode.children, colNode => {
|
|
|
const min = colNode.attributes.min;
|
|
|
const max = colNode.attributes.max;
|
|
|
for (let i = min; i <= max; i++) {
|
|
|
@@ -1488,7 +1488,7 @@ class Sheet {
|
|
|
|
|
|
// Search for a preset that matches existing attributes.
|
|
|
for (const presetName in this._pageMarginsPresets) {
|
|
|
- if (isEqual(this._pageMarginsNode.attributes, this._pageMarginsPresets[presetName])) {
|
|
|
+ if (_isEqual(this._pageMarginsNode.attributes, this._pageMarginsPresets[presetName])) {
|
|
|
this._pageMarginsPresetName = presetName;
|
|
|
break;
|
|
|
}
|