Google SheetsとGASでFlash自動処理ループを作る(3/4)
Sheetsの列Aにタスクを書き込むだけで
Flashが自動で処理して列Bに結果を書く。
GASに貼るだけで動くコード:▼
javascriptfunction runFlashBatch() {
const sheet = SpreadsheetApp.getActiveSheet();
const apiKey = 'YOUR_API_KEY';
const rows = sheet.getLastRow();
for (let i = 2; i <= rows; i ) {
const input = sheet.getRange(i, 1).getValue();
if (!input) continue;
const res = UrlFetchApp.fetch(
'
generativelanguage.googleapi…' apiKey,
{
method: 'post',
contentType: 'application/json',
payload: JSON.stringify({
contents: [{ parts: [{ text: input }] }]
})
}
);
const json = JSON.parse(res.getContentText());
const output = json.candidates[0].content.parts[0].text;
sheet.getRange(i, 2).setValue(output);
}
}
-----------------------
100件のタスクを一括処理。
人間がやれば1時間→Flashで3分。