Skip to content

Instantly share code, notes, and snippets.

@yohei-haribou
Created February 9, 2026 23:35
Show Gist options
  • Select an option

  • Save yohei-haribou/5a87acbb68cd2d5ebb0e027e50896f62 to your computer and use it in GitHub Desktop.

Select an option

Save yohei-haribou/5a87acbb68cd2d5ebb0e027e50896f62 to your computer and use it in GitHub Desktop.
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