Clear Row

Script gsheets Verified

by rossmccrann ยท 7/27/2022

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 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
  start_index: number,
11
  end_index: number,
12
) {
13
  const token = gsheets_auth["token"];
14

15
  const DELETE_ROWS_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`;
16

17
  const body = {
18
    requests: [
19
      {
20
        deleteDimension: {
21
          range: {
22
            sheetId: sheetId,
23
            dimension: "ROWS",
24
            startIndex: start_index,
25
            endIndex: end_index,
26
          },
27
        },
28
      },
29
    ],
30
  };
31
  const response = await fetch(DELETE_ROWS_URL, {
32
    method: "POST",
33
    body: JSON.stringify(body),
34
    headers: {
35
      Authorization: "Bearer " + token,
36
      "Content-Type": "application/json",
37
    },
38
  });
39
  const text = await response.json();
40

41
  return "Rows deleted.";
42
}
43

Other submissions
  • Submitted by rossmccrann Deno
    Created 396 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
      start_index: number,
    9
      end_index: number,
    10
    ) {
    11
      const token = gsheets_auth["token"];
    12
    
    
    13
      const DELETE_ROWS_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`;
    14
    
    
    15
      const body = {
    16
        requests: [
    17
          {
    18
            deleteDimension: {
    19
              range: {
    20
                sheetId: sheetId,
    21
                dimension: "ROWS",
    22
                startIndex: start_index,
    23
                endIndex: end_index,
    24
              },
    25
            },
    26
          },
    27
        ],
    28
      };
    29
      const response = await fetch(DELETE_ROWS_URL, {
    30
        method: "POST",
    31
        body: JSON.stringify(body),
    32
        headers: {
    33
          Authorization: "Bearer " + token,
    34
          "Content-Type": "application/json",
    35
        },
    36
      });
    37
      const text = await response.json();
    38
    
    
    39
      return "Rows deleted.";
    40
    }
    41