1

Clear All Values

by
Published Jul 27, 2022
Script gsheets Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
type Gsheets = {
4
  token: string;
5
};
6
export async function main(
7
  gsheets_auth: Gsheets,
8
  spreadsheetId: string,
9
  sheetId: number,
10
) {
11
  const token = gsheets_auth["token"];
12

13
  const ADD_WORKSHEET_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`;
14

15
  const body = {
16
    requests: [
17
      {
18
        updateCells: {
19
          range: {
20
            sheetId: sheetId,
21
          },
22
          fields: "userEnteredValue",
23
        },
24
      },
25
    ],
26
  };
27

28
  const response = await fetch(ADD_WORKSHEET_URL, {
29
    method: "POST",
30
    body: JSON.stringify(body),
31
    headers: {
32
      Authorization: "Bearer " + token,
33
      "Content-Type": "application/json",
34
    },
35
  });
36

37
  return await response.text();
38
}
39

Other submissions
  • Submitted by rossmccrann Deno
    Created 398 days ago
    1
    type Gsheets = {
    2
      token: string;
    3
    };
    4
    export async function main(
    5
      gsheets_auth: Gsheets,
    6
      spreadsheetId: string,
    7
      sheetId: number,
    8
    ) {
    9
      const token = gsheets_auth["token"];
    10
    
    
    11
      const ADD_WORKSHEET_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`;
    12
    
    
    13
      const body = {
    14
        requests: [
    15
          {
    16
            updateCells: {
    17
              range: {
    18
                sheetId: sheetId,
    19
              },
    20
              fields: "userEnteredValue",
    21
            },
    22
          },
    23
        ],
    24
      };
    25
    
    
    26
      const response = await fetch(ADD_WORKSHEET_URL, {
    27
        method: "POST",
    28
        body: JSON.stringify(body),
    29
        headers: {
    30
          Authorization: "Bearer " + token,
    31
          "Content-Type": "application/json",
    32
        },
    33
      });
    34
    
    
    35
      return await response.text();
    36
    }
    37