| 265 | } |
| 266 | |
| 267 | spliceColumns(start, count, ...inserts) { |
| 268 | const rows = this._rows; |
| 269 | const nRows = rows.length; |
| 270 | if (inserts.length > 0) { |
| 271 | // must iterate over all rows whether they exist yet or not |
| 272 | for (let i = 0; i < nRows; i++) { |
| 273 | const rowArguments = [start, count]; |
| 274 | // eslint-disable-next-line no-loop-func |
| 275 | inserts.forEach(insert => { |
| 276 | rowArguments.push(insert[i] || null); |
| 277 | }); |
| 278 | const row = this.getRow(i + 1); |
| 279 | // eslint-disable-next-line prefer-spread |
| 280 | row.splice.apply(row, rowArguments); |
| 281 | } |
| 282 | } else { |
| 283 | // nothing to insert, so just splice all rows |
| 284 | this._rows.forEach(r => { |
| 285 | if (r) { |
| 286 | r.splice(start, count); |
| 287 | } |
| 288 | }); |
| 289 | } |
| 290 | |
| 291 | // splice column definitions |
| 292 | const nExpand = inserts.length - count; |
| 293 | const nKeep = start + count; |
| 294 | const nEnd = this._columns.length; |
| 295 | if (nExpand < 0) { |
| 296 | for (let i = start + inserts.length; i <= nEnd; i++) { |
| 297 | this.getColumn(i).defn = this.getColumn(i - nExpand).defn; |
| 298 | } |
| 299 | } else if (nExpand > 0) { |
| 300 | for (let i = nEnd; i >= nKeep; i--) { |
| 301 | this.getColumn(i + nExpand).defn = this.getColumn(i).defn; |
| 302 | } |
| 303 | } |
| 304 | for (let i = start; i < start + inserts.length; i++) { |
| 305 | this.getColumn(i).defn = null; |
| 306 | } |
| 307 | |
| 308 | // account for defined names |
| 309 | this.workbook.definedNames.spliceColumns(this.name, start, count, inserts.length); |
| 310 | } |
| 311 | |
| 312 | get lastColumn() { |
| 313 | return this.getColumn(this.columnCount); |