対象
- 楽天ペイの利用明細をGmailで受け取っている方
- 本スクリプトを理解して自分用にカスタマイズ可能な方
利用方法
Googleドライブ -> 新規 -> Googleスプレッドシート -> 拡張機能 -> App Script
myFunctionを差し替えて[実行]
スクリプト
function myFunction() {
const setting = {
query:"from:楽天ペイ after:2024/1/1 before:2025/1/1 ご利用明細",
max:10,
keywords:["ご利用日時","伝票番号","ご利用店舗","電話番号","決済総額","獲得予定ポイント","お取引内容","お支払方法"],
}
const threads = GmailApp.search(setting.query, 0, setting.max);
const messagesForThreads = GmailApp.getMessagesForThreads(threads);
const rows = [setting.keywords];
for(const messages of messagesForThreads){
for(const message of messages){
const plainBody = message.getPlainBody();
const columns = [];
for(const keyword of setting.keywords) {
const matches = plainBody.match(keyword + ".*");
let cellText = "---";
if (matches) {
cellText = matches[0].replace(keyword, "").trim();
}
columns.push(cellText);
}
rows.push(columns);
}
}
const sheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
}
注意事項
- 検索条件は2024年分としています。setting.queryを調整して下さい
- 1日の検索数に制限があるため上限を10スレッドとしています。試して問題が無ければsetting.maxを調整して下さい
- 特殊なケースは一切考慮していません。自己責任でご利用、改変お願いします