2018-12-06 14:51:44 UNSELECTED

Unknown type code

Copy Copied! Full
//For Google Apps Script function updateCalendar(){ //IDを指定してカレンダーを取得 var updateImageFileId = "";//VRC Panorama参照用画像ファイルID var calendarId = '';//GoogleCalendarID var presentationId = "";//編集用スライドID var calendar = CalendarApp.getCalendarById(calendarId); var date = new Date(); var date_D = new Date(date.getFullYear(),date.getMonth(),date.getDate(),0,0,0); var dayStr = [ "Sun.", "Mon.", "Tue.", "Wed.", "Thu.", "Fri.", "Sat." ]; for(var j=0;j<7;j++){ //日付の更新 var startDate = new Date(date_D.getTime()+(24*60*60*1000)*j); var endDate = new Date(date_D.getTime()+(24*60*60*1000)*(j+1)); var events = calendar.getEvents(startDate,endDate); updateTable(presentationId,j,0,(startDate.getMonth()+1)+"/"+startDate.getDate()+"\n"+dayStr[startDate.getDay()]); //イベントの更新 var titles = ""; for (var i=0; i < events.length; i++) { var title = events[i].getTitle(); titles = titles+"・"+title+"\n"; var startTime = events[i].getStartTime(); Logger.log((startTime.getMonth()+1)+"/"+startTime.getDate()+" "+dayStr[startDate.getDay()]+" "+title); } if(titles == "") titles = " ";//セル内が空白だとエラーになるため updateTable(presentationId,j,1,titles); } var blob = generateScreenshot(presentationId,SlidesApp.openById(presentationId).getSlides()[0]); updateFile(DriveApp.getFileById(updateImageFileId).getName(),updateImageFileId,blob.getAs('image/png')); } function updateFile(title,id,blob) { var body = { title: title, mimeType: 'image/png' }; file = Drive.Files.update(body,id, blob); } function generateScreenshot(presentationId,slide) { var response = Slides.Presentations.Pages.getThumbnail(presentationId, slide.getObjectId()); Logger.log(response); var blob = UrlFetchApp.fetch(response.contentUrl).getBlob(); //DriveApp.createFile(blob).setName("Image " + (1) + ".png");//確認用 return blob; } //確認用 function tableTest(){ updateTable("1dKO0aG-NEnwq_AJkCfCFtIQa_pxC0xKdQvzfh62-p44",0,0,"CCCC\nAAA"); } //表の中のテキストを置き換える //置き換える表のセル内が空欄だとエラーになる function updateTable(presentationId,columnIndex,rowIndex,text) { var presentation = Slides.Presentations.get(presentationId); var slide = presentation.slides[0]; var pageElements = slide["pageElements"]; for(var i =0;i<pageElements.length;i++){ var element = pageElements[i]; var objectId = pageElements[i]["objectId"]; if("table"in element){ var table = element["table"]; var requests=[ { "deleteText":{ "objectId":objectId, "cellLocation":{ "rowIndex":rowIndex, "columnIndex":columnIndex }, "textRange":{ "type":"ALL" } }, },{ "insertText":{ "objectId":objectId, "cellLocation":{ "rowIndex":rowIndex, "columnIndex":columnIndex }, "text":text, "insertionIndex":0 } } ]; Slides.Presentations.batchUpdate({"requests":requests},presentationId); } } }
RECOMMEND