Created
January 30, 2022 03:50
-
-
Save neno-tech/d8e76234118c17f177020ac78f25401f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
var folder = DriveApp.getFolderById('xxx');//ไอดีโฟลเดอร์ | |
var date = Utilities.formatDate(new Date(),'GMT+7','dd/MM/yyyy') | |
var contentType = data.substring(5, data.indexOf(';')), | |
bytes = Utilities.base64Decode(data.substr(data.indexOf('base64,') + 7)), | |
blob = Utilities.newBlob(bytes, contentType, file), | |
file = folder.createFolder([name,date].join(" ")).createFile(blob), | |
filelink = file.getUrl(); | |
var lock = LockService.getPublicLock(); | |
lock.waitLock(30000); | |
var doc = SpreadsheetApp.openById('xxx'); | |
var sheet = doc.getSheetByName('ชีต1'); | |
sheet.appendRow([new Date(),name,filelink]) | |
var headRow = 1; | |
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]; | |
var nextRow = sheet.getLastRow() + 1; | |
var row = []; | |
for (i in headers) { | |
if (headers[i] == "วันที่") { | |
row.push(new Date()); | |
} else if (headers[i] == "ชื่อ สกุล") { | |
row.push(name); | |
} else if (headers[i] == "โรงเรียน") { | |
row.push(school); | |
} else if (headers[i] == "อีเมล") { | |
row.push(email); | |
} else if (headers[i] == "เบอร์โทร") { | |
row.push('0'+tel.toString()) | |
} else if (headers[i] == "ลิ้งค์ไฟล์") { | |
row.push(filelink); | |
} | |
} | |
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]); | |
return "success"; | |
} catch (f) { | |
return f.toString(); | |
} finally { | |
lock.releaseLock(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment