Sam
Sam

Reputation: 159

Sheets API Method spreadsheets.values.clear is clearing data validation when it shouldn't?

I'm trying to clear all the values from a Google Sheets sheet, while keeping the formatting and data validation (e.g. dropdowns and checkboxes). The documentation for the spreadsheets.values.clear API method says,

Only values are cleared -- all other properties of the cell (such as formatting, data validation, etc..) are kept.

However, when I run this method, the data validations I have set up on the sheet are deleted.

I suppose I'm both trying to report a bug (the support website directs me to StackOverflow), and also soliciting any suggestions for how I might accomplish the "clear all values but leave formatting and data validation" task.

Upvotes: 0

Views: 43

Answers (1)

Dan
Dan

Reputation: 1

I just tried it myself on bound script against a basic sheet with data in a few columns and rows and it worked fine. It cleared only the data and left the formatting and data validation. The function was as follows :

function myFunction() {
  let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  let range = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn());
  range.clear();
}

Are you running this bound, or unbound? How are you selecting the range?

Upvotes: 0

Related Questions