| 293 | } |
| 294 | |
| 295 | commit() { |
| 296 | // changes may have been made that might have on-sheet effects |
| 297 | if (!this._cache) { |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | // check things are ok first |
| 302 | this.validate(); |
| 303 | |
| 304 | const ref = colCache.decodeAddress(this._cache.ref); |
| 305 | if (this.ref !== this._cache.ref) { |
| 306 | // wipe out whole table footprint at previous location |
| 307 | for (let i = 0; i < this._cache.tableHeight; i++) { |
| 308 | const row = this.worksheet.getRow(ref.row + i); |
| 309 | for (let j = 0; j < this._cache.width; j++) { |
| 310 | const cell = row.getCell(ref.col + j); |
| 311 | cell.value = null; |
| 312 | } |
| 313 | } |
| 314 | } else { |
| 315 | // clear out below table if it has shrunk |
| 316 | for (let i = this.tableHeight; i < this._cache.tableHeight; i++) { |
| 317 | const row = this.worksheet.getRow(ref.row + i); |
| 318 | for (let j = 0; j < this._cache.width; j++) { |
| 319 | const cell = row.getCell(ref.col + j); |
| 320 | cell.value = null; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // clear out to right of table if it has lost columns |
| 325 | for (let i = 0; i < this.tableHeight; i++) { |
| 326 | const row = this.worksheet.getRow(ref.row + i); |
| 327 | for (let j = this.width; j < this._cache.width; j++) { |
| 328 | const cell = row.getCell(ref.col + j); |
| 329 | cell.value = null; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | this.store(); |
| 335 | } |
| 336 | |
| 337 | addRow(values, rowNumber) { |
| 338 | // Add a row of data, either insert at rowNumber or append |