advanced google apps script programming #1 · 2016-01-22 · advanced google apps script...

18
Advanced Google Apps Script Programming #1 https://goo.gl/I8 oktl ทยากร นายคณกรณ หอศ ธรรม นายศ พงษ วรรณ นายเกร ยงไกร หน ทองค มหาว ทยาลัยสงขลานคร นทร WUNCA 32 nd @ Suranaree University of Technology 22 January 2559

Upload: others

Post on 24-Feb-2020

40 views

Category:

Documents


1 download

TRANSCRIPT

Advanced Google Apps Script Programming #1

https://goo.gl/I8oktl  

 

วทิยากร

นายคณกรณ ์หอศริธิรรม  นายศริพิงษ ์ศริวิรรณ 

นายเกรยีงไกร หนูทองคาํ  

มหาวทิยาลัยสงขลานครนิทร ์ 

WUNCA 32nd @ Suranaree University of Technology

22 January 2559

Advanced Google Apps Script Programming #1

Introduction to Google Apps Script: ปพูื้นฐานสาํหรับผูที่ไมเคยใช Google Apps Scripts มากอน

เริ่มจากคาํสัง่พื้นฐานในการเขยีนโปรแกรม การวนลปู เงื่อนไข ไปจนกระทัง่การเขยีน Function

ตอบแบบสาํรวจ

http://goo.gl/forms/lxyuj8mjwG

https://sysadmin.psu.ac.th/2015/05/06/gasws-1/

https://sysadmin.psu.ac.th/2015/05/07/gasws-1-01/

●Google Apps Scripts Workshop – Level 1

●เริ่มตนใชงาน GAS Editor

●ลอ็กอนิ Google Account แลวไปที่ Google Drive

●ตัง้ชื่อ GASWS1

●ตัง้ชื่อ myproject1 กด OK.

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 1/18

Advanced Google Apps Script Programming #1

●ตัง้ชื่อ myscript1

●แกไข myFunction() โดยเพิ่มขอความ

●กดปุม File -> Save หรอืกดปุม ctrl + s

●เมน ูRun > myFunction

●ดผูลไดที่ เมน ูView > Logs หรอื กดปุม Ctrl+Enter

●สราง function myForLoop ดังนี้ 

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 2/18

Advanced Google Apps Script Programming #1

●เมน ูFile > New > Script File

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 3/18

Advanced Google Apps Script Programming #1

●ตัง้ชื่อ myscript2

●สราง function myDate ดังนี้ 

●การตัง้เวลาให project ทาํงานสามารถเลอืกไดจากเมน ูResources > All yours

triggers 

●การทาํ comment สามารถใชสัญลักษณ // หรอื /*

คลายกับลักษณะการคอมเมนทในภาษา C

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 4/18

Advanced Google Apps Script Programming #1

Workshop 1: เขยีนอานขอมลูกับ Google Sheets เกี่ยวกับใชงาน Google Sheets เปนฐานขอมลู

●อาน/เขยีนขอมลูกับ Google Sheets

https://sysadmin.psu.ac.th/2015/05/06/gasws-1-03/

●สราง script ใหมชื่อ myscript3 โดย เมนู File > New > Script File 

●ตัง้ชื่อ myscript3

●เมน ูRun > insertData1

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 5/18

Advanced Google Apps Script Programming #1

●สรางตัวแปร v3 โดยใสขอมลูสวนตัว

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 6/18

Advanced Google Apps Script Programming #1

กดปุม Run -> Insertdata1 ดผูลลัพธในแฟม Sheet

 

●สราง function insertData2() ตามนี้

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 7/18

Advanced Google Apps Script Programming #1

●ตองการให Run ทกุนาท ีเลอืกเมน ูResource -> All your triggers

●ดผูลลัพธจาก Sheet จะเหน็การเปลี่ยนแปลง

●Google limitQuotas for Google Services https://developers.google.com/apps-script/guides/services/quotas?hl=en

●สราง function readData1() ตามนี้

●เปดเมน ูTools > Script Editor…

 

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 8/18

Advanced Google Apps Script Programming #1

 

 

● สรา้ง Sheet ใหม ่ชื่อ “ReadData” โดยกดปุ่มเครื่องหมาย + 

●เปดแฟม https://docs.google.com/spreadsheets/d/1oztRXjC2KJzrqC3LtiRnUPrEgohX4VTYHixylvtCdzY/edit?usp=sharing

● สรา้ง function insertData3() ตามนี้

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 9/18

Advanced Google Apps Script Programming #1

https://sysadmin.psu.ac.th/2015/05/15/gasws-1-05/

แทนที่ขอความ ดวยคาใน Google Sheets ● ใน Google Sheet: GASWS1 

● สรา้ง Sheet ใหม ่ชื่อ “Salary” 

● ใน 5 คน ขอให ้1 คนเปน็  

○ คณกรณ ์หอศริธิรรม [email protected] 

○ สรา้ง Sheet ใหม ่ชื่อ “Template” 

○ ใสข่อ้มลู 

○ A1: เรยีน คณุ{Firstname} {Lastname} 

○ A2: จะม ี{SalaryDetail} จาํนวน {Salary} บาท โอนใหค้ณุในวันที่ {TransferDate} 

○ A3: จงึเรยีนมาเพื่อทราบ 

○ A4: การเงนิ 

○ เมนู Tools > Script Editor… 

○ เมนู File > New > Script File 

○ ตัง้ชื่อ: myscript5 

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 10/18

Advanced Google Apps Script Programming #1

https://sysadmin.psu.ac.th/2015/05/18/gasws-1-06/

สราง Google Docs ใหมใน Google Drive แลวตัง้ชื่อตามตองการ จากนัน้

ใสขอความตอไปนี้ลงไป

เรยีน คณุ{Firstname} {Lastname} 

จะม ี{SalaryDetail} จาํนวน {Salary} บาท โอนใหค้ณุในวันที่ {TransferDate} จงึเรยีนมาเพื่อทราบ 

การเงนิ   Reference https://developers.google.com/apps­script/  

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 11/18

Advanced Google Apps Script Programming #1

Workshop 2: การสราง Mail Merge พื้นฐาน จากขอมลูใน Google Sheets สามารถสรางจดหมายเวยีนไดอยางไร

https://sysadmin.psu.ac.th/2015/05/20/gasws-1-07/

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 12/18

Advanced Google Apps Script Programming #1

Workshop 3: การสราง Self­Destroy Email จาก Google Sheets สามารถนาํมาสรางเปน Google Docs หรอื PDF แลวสง email

เมื่อผูอานอานจดหมายเสรจ็แลว จะทาํลายตัวเองในเวลาที่กาํหนดได

https://sysadmin.psu.ac.th/2015/05/22/top-secret/

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 13/18

Advanced Google Apps Script Programming #1

Workshop 4: การเกบ็ขอมลูจาก Web Page แลวนาํไปวเิคราะห ตองการเกบ็ขอมลูที่ทางเวบ็ไซตมกีารเปลี่ยนแปลงในชวงเวลาหนึ่งๆเปนประจาํ

จะตัง้เวลาใหระบบไปเกบ็ขอมลูแลวนาํมาเขยีนลง Google Sheets เพื่อวเิคราะหไดอยางไร

https://sysadmin.psu.ac.th/2015/05/06/gasws-1-04/

https://sysadmin.psu.ac.th/2015/05/14/gas-web-data-extract/

http://www.bloomberg.com/quote/WGHCEPA:ID

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 14/18

Advanced Google Apps Script Programming #1

Demo 5: การใชงาน API ตางๆ สาํหรับ API ตางๆที่เปนประโยชนเพื่อไปใชงานตอไป พรอมตัวอยางที่นาสนใจ

https://sysadmin.psu.ac.th/2015/05/22/gasws-1-08/

https://sysadmin.psu.ac.th/2014/10/11/googleappsscript-googlesheet-websitemoni

toring/

https://sysadmin.psu.ac.th/2014/11/02/googlesheets-newaccount-suborganization-

gas/

https://sysadmin.psu.ac.th/2015/09/08/google-classroom-manager/

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 15/18

Advanced Google Apps Script Programming #1

Demo 6: การใชรวมกับ Google BigQuery มขีอมลูขนาดมากกวา 1 TB ใน Google BigQuery

สามารถสงผลการคนหาออกมาวเิคราะหสรปุผลดวย Google Sheets ไดอยางไร

https://goo.gl/3XYjMR

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 16/18

Advanced Google Apps Script Programming #1

Demo 7: การใชรวมกับ Google Prediction API การใชงาน Machine Learning ดวย Google Prediction API บน Google Sheets

https://cloud.google.com/prediction/docs?hl=en

WUNCA 32nd @ Suranaree University of Technology 22 January 2559 17/18