1
Create Worksheet
One script reply has been approved by the moderators Verified
Created by rossmccrann 863 days ago Viewed 10284 times
0
Submitted by rossmccrann Deno
Verified 862 days ago
1
type Gsheets = {
2
  token: string;
3
};
4
export async function main(
5
  gsheets_auth: Gsheets,
6
  spreadsheetId: string,
7
  title: string,
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
        addSheet: {
17
          properties: {
18
            title: title,
19
            gridProperties: {
20
              rowCount: 20,
21
              columnCount: 12,
22
            },
23
            tabColor: {
24
              red: 1.0,
25
              green: 0.3,
26
              blue: 0.4,
27
            },
28
          },
29
        },
30
      },
31
    ],
32
  };
33

34
  const response = await fetch(ADD_WORKSHEET_URL, {
35
    method: "POST",
36
    body: JSON.stringify(body),
37
    headers: {
38
      Authorization: "Bearer " + token,
39
      "Content-Type": "application/json",
40
    },
41
  });
42

43
  return await response.text();
44
}
45