google-spreadsheet 5.0.3 → 5.1.0

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/index.cjs CHANGED
@@ -89,6 +89,14 @@ var GoogleSpreadsheetRow = class {
89
89
  _updateRowNumber(newRowNumber) {
90
90
  this._rowNumber = newRowNumber;
91
91
  }
92
+ /**
93
+ * @internal
94
+ * Used internally to mark row as deleted.
95
+ * Should not be called directly.
96
+ */
97
+ _markDeleted() {
98
+ this._deleted = true;
99
+ }
92
100
  get a1Range() {
93
101
  return [
94
102
  this._worksheet.a1SheetName,
@@ -192,6 +200,7 @@ var GoogleSpreadsheetCell = class {
192
200
  _rawData;
193
201
  _draftData = {};
194
202
  _error;
203
+ _deleted = false;
195
204
  constructor(_sheet, _rowIndex, _columnIndex, rawCellData) {
196
205
  this._sheet = _sheet;
197
206
  this._rowIndex = _rowIndex;
@@ -199,6 +208,9 @@ var GoogleSpreadsheetCell = class {
199
208
  this._updateRawData(rawCellData);
200
209
  this._rawData = rawCellData;
201
210
  }
211
+ get deleted() {
212
+ return this._deleted;
213
+ }
202
214
  /**
203
215
  * update cell using raw CellData coming back from sheets API
204
216
  * @internal
@@ -224,6 +236,23 @@ var GoogleSpreadsheetCell = class {
224
236
  get a1Address() {
225
237
  return `${this.a1Column}${this.a1Row}`;
226
238
  }
239
+ /**
240
+ * @internal
241
+ * Used internally to update cell indices after deleting rows/columns.
242
+ * Should not be called directly.
243
+ */
244
+ _updateIndices(rowIndex, columnIndex) {
245
+ this._rowIndex = rowIndex;
246
+ this._columnIndex = columnIndex;
247
+ }
248
+ /**
249
+ * @internal
250
+ * Used internally to mark cell as deleted.
251
+ * Should not be called directly.
252
+ */
253
+ _markDeleted() {
254
+ this._deleted = true;
255
+ }
227
256
  get value() {
228
257
  if (this._draftData.value !== void 0) throw new Error("Value has been changed");
229
258
  if (this._error) return this._error;
@@ -231,6 +260,7 @@ var GoogleSpreadsheetCell = class {
231
260
  return es_toolkit_compat.values(this._rawData.effectiveValue)[0];
232
261
  }
233
262
  set value(newValue) {
263
+ if (this._deleted) throw new Error("This cell has been deleted - reload cells before making updates.");
234
264
  if (newValue instanceof GoogleSpreadsheetCellErrorValue) throw new Error("You can't manually set a value to an error");
235
265
  if (es_toolkit_compat.isBoolean(newValue)) this._draftData.valueType = "boolValue";
236
266
  else if (es_toolkit_compat.isString(newValue)) if (newValue.substring(0, 1) === "=") this._draftData.valueType = "formulaValue";
@@ -499,7 +529,9 @@ var GoogleSpreadsheetWorksheet = class {
499
529
  _ensureInfoLoaded() {
500
530
  if (!this._rawProperties) throw new Error("You must call `doc.loadInfo()` again before accessing this property");
501
531
  }
502
- /** clear local cache of sheet data/properties */
532
+ /**
533
+ * clear local cache of sheet data/properties
534
+ */
503
535
  resetLocalCache(dataOnly) {
504
536
  if (!dataOnly) this._rawProperties = null;
505
537
  this._headerValues = void 0;
@@ -731,7 +763,9 @@ var GoogleSpreadsheetWorksheet = class {
731
763
  return new GoogleSpreadsheetRow(this, rowNumber++, rowValues);
732
764
  });
733
765
  }
734
- /** add a single row - see addRows for more info */
766
+ /**
767
+ * add a single row - see addRows for more info
768
+ */
735
769
  async addRow(rowValues, options) {
736
770
  return (await this.addRows([rowValues], options))[0];
737
771
  }
@@ -771,6 +805,79 @@ var GoogleSpreadsheetWorksheet = class {
771
805
  if (row.rowNumber > deletedRowNumber) row._updateRowNumber(row.rowNumber - 1);
772
806
  });
773
807
  }
808
+ /**
809
+ * @internal
810
+ * Used internally to update row numbers after deleting multiple rows.
811
+ * Should not be called directly.
812
+ * */
813
+ _shiftRowCacheBulk(startIndex, endIndex) {
814
+ const numDeleted = endIndex - startIndex;
815
+ const startRow = startIndex + 1;
816
+ const endRow = endIndex;
817
+ for (let rowNum = startRow; rowNum <= endRow; rowNum++) {
818
+ const row = this._rowCache[rowNum];
819
+ if (row) row._markDeleted();
820
+ delete this._rowCache[rowNum];
821
+ }
822
+ this._rowCache.forEach((row) => {
823
+ if (row.rowNumber > endRow) row._updateRowNumber(row.rowNumber - numDeleted);
824
+ });
825
+ }
826
+ /**
827
+ * @internal
828
+ * Used internally to shift cell cache after deleting rows.
829
+ * Should not be called directly.
830
+ * */
831
+ _shiftCellCacheRows(startIndex, endIndex) {
832
+ const numDeleted = endIndex - startIndex;
833
+ for (let rowIndex = startIndex; rowIndex < endIndex; rowIndex++) {
834
+ const row = this._cells[rowIndex];
835
+ if (row) row.forEach((cell) => {
836
+ if (cell) cell._markDeleted();
837
+ });
838
+ delete this._cells[rowIndex];
839
+ }
840
+ const rowsToShift = [];
841
+ for (let rowIndex = endIndex; rowIndex < this._cells.length; rowIndex++) if (this._cells[rowIndex]) rowsToShift.push({
842
+ oldRowIndex: rowIndex,
843
+ cells: this._cells[rowIndex]
844
+ });
845
+ rowsToShift.forEach(({ oldRowIndex, cells }) => {
846
+ delete this._cells[oldRowIndex];
847
+ const newRowIndex = oldRowIndex - numDeleted;
848
+ this._cells[newRowIndex] = cells;
849
+ cells.forEach((cell, colIndex) => {
850
+ if (cell) cell._updateIndices(newRowIndex, colIndex);
851
+ });
852
+ });
853
+ }
854
+ /**
855
+ * @internal
856
+ * Used internally to shift cell cache after deleting columns.
857
+ * Should not be called directly.
858
+ * */
859
+ _shiftCellCacheColumns(startIndex, endIndex) {
860
+ const numDeleted = endIndex - startIndex;
861
+ this._cells.forEach((row, rowIndex) => {
862
+ if (!row) return;
863
+ for (let colIndex = startIndex; colIndex < endIndex; colIndex++) {
864
+ const cell = row[colIndex];
865
+ if (cell) cell._markDeleted();
866
+ delete row[colIndex];
867
+ }
868
+ const cellsToShift = [];
869
+ for (let colIndex = endIndex; colIndex < row.length; colIndex++) if (row[colIndex]) cellsToShift.push({
870
+ oldColIndex: colIndex,
871
+ cell: row[colIndex]
872
+ });
873
+ cellsToShift.forEach(({ oldColIndex, cell }) => {
874
+ delete row[oldColIndex];
875
+ const newColIndex = oldColIndex - numDeleted;
876
+ row[newColIndex] = cell;
877
+ cell._updateIndices(rowIndex, newColIndex);
878
+ });
879
+ });
880
+ }
774
881
  async clearRows(options) {
775
882
  const startRowIndex = options?.start || this._headerRowIndex + 1;
776
883
  const endRowIndex = options?.end || this.rowCount;
@@ -795,12 +902,13 @@ var GoogleSpreadsheetWorksheet = class {
795
902
  async updateGridProperties(gridProperties) {
796
903
  return this.updateProperties({ gridProperties });
797
904
  }
798
- /** resize, internally just calls updateGridProperties */
905
+ /**
906
+ * resize, internally just calls updateGridProperties
907
+ */
799
908
  async resize(gridProperties) {
800
909
  return this.updateGridProperties(gridProperties);
801
910
  }
802
911
  /**
803
- *
804
912
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#updatedimensionpropertiesrequest
805
913
  */
806
914
  async updateDimensionProperties(columnsOrRows, properties, bounds) {
@@ -821,15 +929,96 @@ var GoogleSpreadsheetWorksheet = class {
821
929
  const ranges = a1Ranges.map((r) => `ranges=${this.encodedA1SheetName}!${r}`).join("&");
822
930
  return (await (await this._spreadsheet.sheetsApi.get(`values:batchGet?${ranges}`, { searchParams: options })).json()).valueRanges.map((r) => r.values);
823
931
  }
824
- async updateNamedRange() {}
825
- async addNamedRange() {}
826
- async deleteNamedRange() {}
827
- async repeatCell() {}
828
- async autoFill() {}
829
- async cutPaste() {}
830
- async copyPaste() {}
932
+ /**
933
+ * Updates an existing named range
934
+ *
935
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateNamedRangeRequest
936
+ */
937
+ async updateNamedRange(namedRangeId, namedRange, fields) {
938
+ return this._makeSingleUpdateRequest("updateNamedRange", {
939
+ namedRange: {
940
+ namedRangeId,
941
+ ...namedRange.name && { name: namedRange.name },
942
+ ...namedRange.range && { range: this._addSheetIdToRange(namedRange.range) }
943
+ },
944
+ fields
945
+ });
946
+ }
947
+ /**
948
+ * Creates a new named range in this worksheet (convenience method that auto-fills sheetId)
949
+ *
950
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddNamedRangeRequest
951
+ */
952
+ async addNamedRange(name, range, namedRangeId) {
953
+ return this._spreadsheet.addNamedRange(name, this._addSheetIdToRange(range), namedRangeId);
954
+ }
955
+ /**
956
+ * Deletes a named range (convenience wrapper)
957
+ *
958
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteNamedRangeRequest
959
+ */
960
+ async deleteNamedRange(namedRangeId) {
961
+ return this._spreadsheet.deleteNamedRange(namedRangeId);
962
+ }
963
+ /**
964
+ * Updates all cells in a range with the same cell data
965
+ *
966
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#RepeatCellRequest
967
+ */
968
+ async repeatCell(range, cell, fields) {
969
+ await this._makeSingleUpdateRequest("repeatCell", {
970
+ range: this._addSheetIdToRange(range),
971
+ cell,
972
+ fields
973
+ });
974
+ }
975
+ /**
976
+ * Auto-fills cells with data following a pattern (like dragging the fill handle)
977
+ *
978
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AutoFillRequest
979
+ */
980
+ async autoFill(rangeOrSource, useAlternateSeries) {
981
+ const isSourceAndDestination = "dimension" in rangeOrSource;
982
+ await this._makeSingleUpdateRequest("autoFill", {
983
+ ...isSourceAndDestination ? { sourceAndDestination: {
984
+ ...rangeOrSource,
985
+ source: this._addSheetIdToRange(rangeOrSource.source)
986
+ } } : { range: this._addSheetIdToRange(rangeOrSource) },
987
+ ...useAlternateSeries !== void 0 && { useAlternateSeries }
988
+ });
989
+ }
990
+ /**
991
+ * Cuts data from a source range and pastes it to a destination coordinate
992
+ *
993
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#CutPasteRequest
994
+ */
995
+ async cutPaste(source, destination, pasteType = "PASTE_NORMAL") {
996
+ await this._makeSingleUpdateRequest("cutPaste", {
997
+ source: this._addSheetIdToRange(source),
998
+ destination: {
999
+ sheetId: this.sheetId,
1000
+ rowIndex: destination.rowIndex,
1001
+ columnIndex: destination.columnIndex
1002
+ },
1003
+ pasteType
1004
+ });
1005
+ }
1006
+ /**
1007
+ * Copies data from a source range and pastes it to a destination range
1008
+ *
1009
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#CopyPasteRequest
1010
+ */
1011
+ async copyPaste(source, destination, pasteType = "PASTE_NORMAL", pasteOrientation = "NORMAL") {
1012
+ await this._makeSingleUpdateRequest("copyPaste", {
1013
+ source: this._addSheetIdToRange(source),
1014
+ destination: this._addSheetIdToRange(destination),
1015
+ pasteType,
1016
+ pasteOrientation
1017
+ });
1018
+ }
831
1019
  /**
832
1020
  * Merges all cells in the range
1021
+ *
833
1022
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#MergeCellsRequest
834
1023
  */
835
1024
  async mergeCells(range, mergeType = "MERGE_ALL") {
@@ -840,21 +1029,114 @@ var GoogleSpreadsheetWorksheet = class {
840
1029
  }
841
1030
  /**
842
1031
  * Unmerges cells in the given range
1032
+ *
843
1033
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UnmergeCellsRequest
844
1034
  */
845
1035
  async unmergeCells(range) {
846
1036
  await this._makeSingleUpdateRequest("unmergeCells", { range: this._addSheetIdToRange(range) });
847
1037
  }
848
- async updateBorders() {}
849
- async addFilterView() {}
850
- async appendCells() {}
851
- async clearBasicFilter() {}
852
- async deleteDimension() {}
853
- async deleteEmbeddedObject() {}
854
- async deleteFilterView() {}
855
- async duplicateFilterView() {}
1038
+ /**
1039
+ * Updates borders for a range
1040
+ *
1041
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateBordersRequest
1042
+ */
1043
+ async updateBorders(range, borders) {
1044
+ await this._makeSingleUpdateRequest("updateBorders", {
1045
+ range: this._addSheetIdToRange(range),
1046
+ ...borders
1047
+ });
1048
+ }
1049
+ /**
1050
+ * Adds a filter view to the sheet
1051
+ *
1052
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddFilterViewRequest
1053
+ */
1054
+ async addFilterView(filter) {
1055
+ return this._makeSingleUpdateRequest("addFilterView", { filter });
1056
+ }
1057
+ /**
1058
+ * Appends cells after the last row with data in a sheet
1059
+ *
1060
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AppendCellsRequest
1061
+ */
1062
+ async appendCells(rows, fields) {
1063
+ await this._makeSingleUpdateRequest("appendCells", {
1064
+ sheetId: this.sheetId,
1065
+ rows,
1066
+ fields
1067
+ });
1068
+ }
1069
+ /**
1070
+ * Clears the basic filter on this sheet
1071
+ *
1072
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#ClearBasicFilterRequest
1073
+ */
1074
+ async clearBasicFilter() {
1075
+ await this._makeSingleUpdateRequest("clearBasicFilter", { sheetId: this.sheetId });
1076
+ }
1077
+ /**
1078
+ * Delete rows or columns in a given range
1079
+ *
1080
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteDimensionRequest
1081
+ */
1082
+ async deleteDimension(columnsOrRows, rangeIndexes) {
1083
+ if (!columnsOrRows) throw new Error("You need to specify a dimension. i.e. COLUMNS|ROWS");
1084
+ if (!es_toolkit_compat.isObject(rangeIndexes)) throw new Error("`range` must be an object containing `startIndex` and `endIndex`");
1085
+ if (!es_toolkit_compat.isInteger(rangeIndexes.startIndex) || rangeIndexes.startIndex < 0) throw new Error("range.startIndex must be an integer >=0");
1086
+ if (!es_toolkit_compat.isInteger(rangeIndexes.endIndex) || rangeIndexes.endIndex < 0) throw new Error("range.endIndex must be an integer >=0");
1087
+ if (rangeIndexes.endIndex <= rangeIndexes.startIndex) throw new Error("range.endIndex must be greater than range.startIndex");
1088
+ const result = await this._makeSingleUpdateRequest("deleteDimension", { range: {
1089
+ sheetId: this.sheetId,
1090
+ dimension: columnsOrRows,
1091
+ startIndex: rangeIndexes.startIndex,
1092
+ endIndex: rangeIndexes.endIndex
1093
+ } });
1094
+ if (columnsOrRows === "ROWS") {
1095
+ this._shiftRowCacheBulk(rangeIndexes.startIndex, rangeIndexes.endIndex);
1096
+ this._shiftCellCacheRows(rangeIndexes.startIndex, rangeIndexes.endIndex);
1097
+ } else this._shiftCellCacheColumns(rangeIndexes.startIndex, rangeIndexes.endIndex);
1098
+ return result;
1099
+ }
1100
+ /**
1101
+ * Delete rows by index
1102
+ */
1103
+ async deleteRows(startIndex, endIndex) {
1104
+ return this.deleteDimension("ROWS", {
1105
+ startIndex,
1106
+ endIndex
1107
+ });
1108
+ }
1109
+ /**
1110
+ * Delete columns by index
1111
+ */
1112
+ async deleteColumns(startIndex, endIndex) {
1113
+ return this.deleteDimension("COLUMNS", {
1114
+ startIndex,
1115
+ endIndex
1116
+ });
1117
+ }
1118
+ async deleteEmbeddedObject() {
1119
+ throw new Error("Not implemented yet");
1120
+ }
1121
+ /**
1122
+ * Deletes a filter view from the sheet
1123
+ *
1124
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteFilterViewRequest
1125
+ */
1126
+ async deleteFilterView(filterId) {
1127
+ await this._makeSingleUpdateRequest("deleteFilterView", { filterId });
1128
+ }
1129
+ /**
1130
+ * Duplicates a filter view
1131
+ *
1132
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DuplicateFilterViewRequest
1133
+ */
1134
+ async duplicateFilterView(filterId) {
1135
+ await this._makeSingleUpdateRequest("duplicateFilterView", { filterId });
1136
+ }
856
1137
  /**
857
1138
  * Duplicate worksheet within the document
1139
+ *
858
1140
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DuplicateSheetRequest
859
1141
  */
860
1142
  async duplicate(options) {
@@ -866,9 +1148,22 @@ var GoogleSpreadsheetWorksheet = class {
866
1148
  })).properties.sheetId;
867
1149
  return this._spreadsheet.sheetsById[newSheetId];
868
1150
  }
869
- async findReplace() {}
1151
+ /**
1152
+ * Finds and replaces text in cells
1153
+ *
1154
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#FindReplaceRequest
1155
+ */
1156
+ async findReplace(find, replacement, options, range) {
1157
+ await this._makeSingleUpdateRequest("findReplace", {
1158
+ find,
1159
+ replacement,
1160
+ ...options,
1161
+ ...range ? { range: this._addSheetIdToRange(range) } : { sheetId: this.sheetId }
1162
+ });
1163
+ }
870
1164
  /**
871
1165
  * Inserts rows or columns at a particular index
1166
+ *
872
1167
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
873
1168
  */
874
1169
  async insertDimension(columnsOrRows, rangeIndexes, inheritFromBefore) {
@@ -891,27 +1186,143 @@ var GoogleSpreadsheetWorksheet = class {
891
1186
  }
892
1187
  /**
893
1188
  * insert empty cells in a range, shifting existing cells in the specified direction
1189
+ *
894
1190
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertRangeRequest
895
1191
  */
896
1192
  async insertRange(range, shiftDimension) {
897
- return this._makeSingleUpdateRequest("insertRange", {
1193
+ await this._makeSingleUpdateRequest("insertRange", {
1194
+ range: this._addSheetIdToRange(range),
1195
+ shiftDimension
1196
+ });
1197
+ }
1198
+ /**
1199
+ * Moves rows or columns to a different position within the sheet
1200
+ *
1201
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#MoveDimensionRequest
1202
+ */
1203
+ async moveDimension(dimension, source, destinationIndex) {
1204
+ await this._makeSingleUpdateRequest("moveDimension", {
1205
+ source: {
1206
+ sheetId: this.sheetId,
1207
+ dimension,
1208
+ startIndex: source.startIndex,
1209
+ endIndex: source.endIndex
1210
+ },
1211
+ destinationIndex
1212
+ });
1213
+ }
1214
+ async updateEmbeddedObjectPosition() {
1215
+ throw new Error("Not implemented yet");
1216
+ }
1217
+ /**
1218
+ * Inserts data into the spreadsheet starting at the specified coordinate
1219
+ *
1220
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#PasteDataRequest
1221
+ */
1222
+ async pasteData(coordinate, data, delimiter, type = "PASTE_NORMAL") {
1223
+ await this._makeSingleUpdateRequest("pasteData", {
1224
+ coordinate: {
1225
+ sheetId: this.sheetId,
1226
+ rowIndex: coordinate.rowIndex,
1227
+ columnIndex: coordinate.columnIndex
1228
+ },
1229
+ data,
1230
+ delimiter,
1231
+ type
1232
+ });
1233
+ }
1234
+ /**
1235
+ * Splits a column of text into multiple columns based on a delimiter
1236
+ *
1237
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#TextToColumnsRequest
1238
+ */
1239
+ async textToColumns(source, delimiterType, delimiter) {
1240
+ await this._makeSingleUpdateRequest("textToColumns", {
1241
+ source: this._addSheetIdToRange(source),
1242
+ delimiterType,
1243
+ ...delimiter && { delimiter }
1244
+ });
1245
+ }
1246
+ /**
1247
+ * Updates properties of a filter view
1248
+ *
1249
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateFilterViewRequest
1250
+ */
1251
+ async updateFilterView(filter, fields) {
1252
+ await this._makeSingleUpdateRequest("updateFilterView", {
1253
+ filter,
1254
+ fields
1255
+ });
1256
+ }
1257
+ /**
1258
+ * Deletes a range of cells and shifts remaining cells
1259
+ *
1260
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteRangeRequest
1261
+ */
1262
+ async deleteRange(range, shiftDimension) {
1263
+ await this._makeSingleUpdateRequest("deleteRange", {
898
1264
  range: this._addSheetIdToRange(range),
899
1265
  shiftDimension
900
1266
  });
901
1267
  }
902
- async moveDimension() {}
903
- async updateEmbeddedObjectPosition() {}
904
- async pasteData() {}
905
- async textToColumns() {}
906
- async updateFilterView() {}
907
- async deleteRange() {}
908
- async appendDimension() {}
909
- async addConditionalFormatRule() {}
910
- async updateConditionalFormatRule() {}
911
- async deleteConditionalFormatRule() {}
912
- async sortRange() {}
1268
+ /**
1269
+ * Appends rows or columns to the end of a sheet
1270
+ *
1271
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AppendDimensionRequest
1272
+ */
1273
+ async appendDimension(dimension, length) {
1274
+ await this._makeSingleUpdateRequest("appendDimension", {
1275
+ sheetId: this.sheetId,
1276
+ dimension,
1277
+ length
1278
+ });
1279
+ }
1280
+ /**
1281
+ * Adds a new conditional formatting rule at the given index
1282
+ * All subsequent rules' indexes are incremented
1283
+ *
1284
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddConditionalFormatRuleRequest
1285
+ */
1286
+ async addConditionalFormatRule(rule, index) {
1287
+ await this._makeSingleUpdateRequest("addConditionalFormatRule", {
1288
+ rule,
1289
+ index
1290
+ });
1291
+ }
1292
+ /**
1293
+ * Updates a conditional format rule at the given index, or moves a conditional format rule to another index
1294
+ *
1295
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateConditionalFormatRuleRequest
1296
+ */
1297
+ async updateConditionalFormatRule(options) {
1298
+ await this._makeSingleUpdateRequest("updateConditionalFormatRule", options);
1299
+ }
1300
+ /**
1301
+ * Deletes a conditional format rule at the given index
1302
+ * All subsequent rules' indexes are decremented
1303
+ *
1304
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteConditionalFormatRuleRequest
1305
+ */
1306
+ async deleteConditionalFormatRule(index, sheetId) {
1307
+ await this._makeSingleUpdateRequest("deleteConditionalFormatRule", {
1308
+ index,
1309
+ sheetId: sheetId ?? this.sheetId
1310
+ });
1311
+ }
1312
+ /**
1313
+ * Sorts data in rows based on sort order per column
1314
+ *
1315
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#SortRangeRequest
1316
+ */
1317
+ async sortRange(range, sortSpecs) {
1318
+ await this._makeSingleUpdateRequest("sortRange", {
1319
+ range: this._addSheetIdToRange(range),
1320
+ sortSpecs
1321
+ });
1322
+ }
913
1323
  /**
914
1324
  * Sets (or unsets) a data validation rule to every cell in the range
1325
+ *
915
1326
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#SetDataValidationRequest
916
1327
  */
917
1328
  async setDataValidation(range, rule) {
@@ -923,9 +1334,20 @@ var GoogleSpreadsheetWorksheet = class {
923
1334
  ...rule && { rule }
924
1335
  });
925
1336
  }
926
- async setBasicFilter() {}
1337
+ /**
1338
+ * Sets the basic filter on this sheet
1339
+ *
1340
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#SetBasicFilterRequest
1341
+ */
1342
+ async setBasicFilter(filter) {
1343
+ await this._makeSingleUpdateRequest("setBasicFilter", { filter: {
1344
+ ...filter,
1345
+ ...filter.range && { range: this._addSheetIdToRange(filter.range) }
1346
+ } });
1347
+ }
927
1348
  /**
928
1349
  * add a new protected range to the sheet
1350
+ *
929
1351
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddProtectedRangeRequest
930
1352
  */
931
1353
  async addProtectedRange(protectedRange) {
@@ -934,6 +1356,7 @@ var GoogleSpreadsheetWorksheet = class {
934
1356
  }
935
1357
  /**
936
1358
  * update an existing protected range
1359
+ *
937
1360
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateProtectedRangeRequest
938
1361
  */
939
1362
  async updateProtectedRange(protectedRangeId, protectedRange) {
@@ -947,6 +1370,7 @@ var GoogleSpreadsheetWorksheet = class {
947
1370
  }
948
1371
  /**
949
1372
  * delete a protected range by ID
1373
+ *
950
1374
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteProtectedRangeRequest
951
1375
  */
952
1376
  async deleteProtectedRange(protectedRangeId) {
@@ -954,6 +1378,7 @@ var GoogleSpreadsheetWorksheet = class {
954
1378
  }
955
1379
  /**
956
1380
  * auto-resize rows or columns to fit their contents
1381
+ *
957
1382
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AutoResizeDimensionsRequest
958
1383
  */
959
1384
  async autoResizeDimensions(columnsOrRows, rangeIndexes) {
@@ -963,34 +1388,126 @@ var GoogleSpreadsheetWorksheet = class {
963
1388
  ...rangeIndexes
964
1389
  } });
965
1390
  }
966
- async addChart() {}
967
- async updateChartSpec() {}
968
- async updateBanding() {}
969
- async addBanding() {}
970
- async deleteBanding() {}
971
- async createDeveloperMetadata() {}
972
- async updateDeveloperMetadata() {}
973
- async deleteDeveloperMetadata() {}
974
- async randomizeRange() {}
975
- async addDimensionGroup() {}
976
- async deleteDimensionGroup() {}
977
- async updateDimensionGroup() {}
978
- async trimWhitespace() {}
979
- async deleteDuplicates() {}
980
- async addSlicer() {}
981
- async updateSlicerSpec() {}
982
- /** delete this worksheet */
1391
+ async addChart() {
1392
+ throw new Error("Not implemented yet");
1393
+ }
1394
+ async updateChartSpec() {
1395
+ throw new Error("Not implemented yet");
1396
+ }
1397
+ /**
1398
+ * Updates properties of a banded range
1399
+ *
1400
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateBandingRequest
1401
+ */
1402
+ async updateBanding(bandedRange, fields) {
1403
+ await this._makeSingleUpdateRequest("updateBanding", {
1404
+ bandedRange,
1405
+ fields
1406
+ });
1407
+ }
1408
+ /**
1409
+ * Adds a new banded range to the sheet
1410
+ *
1411
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddBandingRequest
1412
+ */
1413
+ async addBanding(bandedRange) {
1414
+ return this._makeSingleUpdateRequest("addBanding", { bandedRange });
1415
+ }
1416
+ /**
1417
+ * Deletes a banded range from the sheet
1418
+ *
1419
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteBandingRequest
1420
+ */
1421
+ async deleteBanding(bandedRangeId) {
1422
+ await this._makeSingleUpdateRequest("deleteBanding", { bandedRangeId });
1423
+ }
1424
+ /**
1425
+ * Creates developer metadata
1426
+ *
1427
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#CreateDeveloperMetadataRequest
1428
+ */
1429
+ async createDeveloperMetadata(developerMetadata) {
1430
+ return this._makeSingleUpdateRequest("createDeveloperMetadata", { developerMetadata });
1431
+ }
1432
+ /**
1433
+ * Updates developer metadata that matches the specified filters
1434
+ *
1435
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateDeveloperMetadataRequest
1436
+ */
1437
+ async updateDeveloperMetadata(dataFilters, developerMetadata, fields) {
1438
+ await this._makeSingleUpdateRequest("updateDeveloperMetadata", {
1439
+ dataFilters,
1440
+ developerMetadata,
1441
+ fields
1442
+ });
1443
+ }
1444
+ /**
1445
+ * Deletes developer metadata that matches the specified filter
1446
+ *
1447
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteDeveloperMetadataRequest
1448
+ */
1449
+ async deleteDeveloperMetadata(dataFilter) {
1450
+ await this._makeSingleUpdateRequest("deleteDeveloperMetadata", { dataFilter });
1451
+ }
1452
+ /**
1453
+ * Randomizes the order of rows in a range
1454
+ *
1455
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#RandomizeRangeRequest
1456
+ */
1457
+ async randomizeRange(range) {
1458
+ await this._makeSingleUpdateRequest("randomizeRange", { range: this._addSheetIdToRange(range) });
1459
+ }
1460
+ async addDimensionGroup() {
1461
+ throw new Error("Not implemented yet");
1462
+ }
1463
+ async deleteDimensionGroup() {
1464
+ throw new Error("Not implemented yet");
1465
+ }
1466
+ async updateDimensionGroup() {
1467
+ throw new Error("Not implemented yet");
1468
+ }
1469
+ /**
1470
+ * Trims whitespace from the start and end of each cell's text
1471
+ *
1472
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#TrimWhitespaceRequest
1473
+ */
1474
+ async trimWhitespace(range) {
1475
+ await this._makeSingleUpdateRequest("trimWhitespace", { range: this._addSheetIdToRange(range) });
1476
+ }
1477
+ /**
1478
+ * Removes duplicate rows from a range based on specified columns
1479
+ *
1480
+ * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteDuplicatesRequest
1481
+ */
1482
+ async deleteDuplicates(range, comparisonColumns) {
1483
+ await this._makeSingleUpdateRequest("deleteDuplicates", {
1484
+ range: this._addSheetIdToRange(range),
1485
+ ...comparisonColumns && { comparisonColumns }
1486
+ });
1487
+ }
1488
+ async addSlicer() {
1489
+ throw new Error("Not implemented yet");
1490
+ }
1491
+ async updateSlicerSpec() {
1492
+ throw new Error("Not implemented yet");
1493
+ }
1494
+ /**
1495
+ * delete this worksheet
1496
+ */
983
1497
  async delete() {
984
1498
  return this._spreadsheet.deleteSheet(this.sheetId);
985
1499
  }
986
1500
  /**
987
1501
  * copies this worksheet into another document/spreadsheet
1502
+ *
988
1503
  * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.sheets/copyTo
989
- * */
1504
+ */
990
1505
  async copyToSpreadsheet(destinationSpreadsheetId) {
991
1506
  return await this._spreadsheet.sheetsApi.post(`sheets/${this.sheetId}:copyTo`, { json: { destinationSpreadsheetId } }).json();
992
1507
  }
993
- /** clear data in the sheet - either the entire sheet or a specific range */
1508
+ /**
1509
+ * clear data in the sheet - either the entire sheet or a specific range
1510
+ */
994
1511
  async clear(a1Range) {
995
1512
  const range = a1Range ? `!${a1Range}` : "";
996
1513
  await this._spreadsheet.sheetsApi.post(`values/${this.encodedA1SheetName}${range}:clear`);