Created
February 9, 2026 23:35
-
-
Save yohei-haribou/5a87acbb68cd2d5ebb0e027e50896f62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { google } from "googleapis"; | |
| async function appendValuesToSpreadsheet() { | |
| const authClient = new google.auth.GoogleAuth({ | |
| keyFilename: "credential.json", | |
| scopes: ["https://www.googleapis.com/auth/spreadsheets"], | |
| }); | |
| const sheetsClient = google.sheets({ | |
| version: "v4", | |
| auth: authClient, | |
| }); | |
| const spreadsheetId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; | |
| const range = "シート1!A1"; | |
| const values = [ | |
| [ | |
| new Date().toLocaleString("ja-JP", { timeZone: "Asia/Tokyo" }), | |
| "山田太郎", | |
| "タイトルです", | |
| "本文です", | |
| ], | |
| ]; | |
| const response = await sheetsClient.spreadsheets.values.append({ | |
| spreadsheetId, | |
| range, | |
| valueInputOption: "RAW", | |
| insertDataOption: "INSERT_ROWS", | |
| requestBody: { | |
| values, | |
| }, | |
| }); | |
| if (response.status !== 200) { | |
| console.error(response); | |
| throw new Error("Failed to append values to spreadsheet"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment