Google sheet – Apps script | TẠO AUTO ID và CUSTOM Unique ID
Giáo án link (giaoan.link) chia sẻ đến các bạn project Google sheet – Apps script | TẠO AUTO ID và CUSTOM Unique ID. Qua ví dụ này bạn sẽ biết cách tạo ID tự động tăng duy nhất khi bạn submit dữ liệu. Ngoài ra bạn có thể kết hợp để tạo các tiếp đầu ngữ cho ID – như một chuỗi text hoặc dãy số ngày-tháng-năm…
Các project excel khác:
- Web App Script CSS JS | Tạo hiệu ứng Click button Nổ tung các mảnh giấy và chuyển link
- Web App Script CSS | Tạo button Liên hệ gồm 3 option đẹp mắt cho trang web
- Web App Script Webapp | Hiệu ứng hoa rơi – Form nhập liệu Gửi nội dung đến email
- Web App Script | Thanh trạng thái Status bar – Giá trị thể hiện theo điểm và label.
- Google sheet Apps script | Data Entry Form – Tự động đọc số tiền thành chữ ở trường input
- Google sheet Apps script | Cập nhật điểm lớp học – Theo danh sách lớp và Theo từng học sinh
- Google sheet, apps script Định dạng dấu phân cách hàng ngàn cho input
- Google sheet apps script | Chọn năm và kiểu biểu đồ để Load dữ liệu lên website
- Google sheet apps script | Scan QR code – Filter and get data table display on webapp
- Google sheet apps script Filter to get data to display on webapp, fill background color for data row
Code trong file “Code.gs”
function addNewRecord() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var shtForm = ss.getSheetByName("Form");
var shtRecords = ss.getSheetByName("Records");
var IDCol = shtRecords.getRange("A2:A").getValues();
var nextID = Math.max.apply(null,IDCol)+1;
var realDate = new Date();
var realDay = realDate.getDate().toString();
var realMonth = realDate.getMonth();
var realMonth1=realMonth + 1;
var realYear = realDate.getFullYear().toString();
var realID = realDay + realMonth1 + realYear + "-" + nextID;
var lastRow = shtRecords.getLastRow()+1;
var myArray = [[nextID,
realID,
shtForm.getRange("C4").getValue(),
shtForm.getRange("C6").getValue(),
shtForm.getRange("C8").getValue(),
shtForm.getRange("C10").getValue()
]];
shtRecords.getRange(lastRow,1,myArray.length,myArray[0].length).setValues(myArray);
shtForm.getRange("C4:C10").clearContent();
}