Google Apps Scriptã§Google Spreadsheetã®å 容ãCSVãã¡ã¤ã«ã«ãã¦æ·»ä»ãã¡ã¤ã«ã§ã¡ã¼ã«ãéã
Google Apps Scriptã§Google SpreadSheetï¼ã¹ãã¬ããã·ã¼ãï¼ã®å
容ãCSVãã¡ã¤ã«ã«ãã¦æ·»ä»ãã¡ã¤ã«ã§ã¡ã¼ã«ãéãã®ãä½ãã¾ããã
A1ããå
容ãæ¸ããã¦ããã®éå®ã§ããã調æ´ãããã¨ãã§ããããããªããã¨æãã¾ãã
以åã«æ¸ãããGoogle Apps Scriptでcronみたいに定期的な処理でメールを送るãã¨çµã¿åãããã¨ãå®æçã«Google SpreadSheetï¼ã¹ãã¬ããã·ã¼ãï¼ã®å
容ãã¡ã¼ã«ã§éããã¨ãã§ããã¨æãã¾ãã
è¨å®
ã¡ã¼ã«ã¢ãã¬ã¹ã®å®å
ãCSVãã¡ã¤ã«åãã©ã®ã·ã¼ããCSVã«ããã®ãã決ãã¾ãã
ä»ã«ããã¡ã¼ã«ã®ã¿ã¤ãã«ããæ¬æãªã©ã決ãããã¨ãã§ãã¾ãã
ã½ã¼ã¹
function attachmentsToCsvFile() { var csvFileName = 'test.csv'; var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('all'); var maxColumn = ss.getLastColumn(); var maxRow = ss.getLastRow(); var data = ss.getRange(1,1,maxRow,maxColumn).getValues(); if (data.length > 1) { var csv = ""; for (var row = 0; row < data.length; row++) { for (var col = 0; col < data[row].length; col++) { if (data[row][col].toString().indexOf(",") != -1) { data[row][col] = "\"" + data[row][col] + "\""; } } if (row < data.length-1) { csv += data[row].join(",") + "\r\n"; } else { csv += data[row]; } } csvFile = csv; } var attachments = [{fileName:csvFileName, mimeType:'text/comma-separated-values', content: csvFile}]; MailApp.sendEmail("[email protected]", "CSV file", "CSV file", {attachments:attachments}); }