Google sheet Apps script, tự động Sắp xếp dữ liệu theo cột bất kỳ (Auto Sort by Column). Sau đây là code được sử dụng trong apps script, bạn có thể xem thêm video hướng dẫn ở bên dưới.
Các bài excel ứng dụng thực tế:
- 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 apps cript
function onOpen(){
autoSort();
}
function onEdit(){
autoSort();
}
function autoSort() {
let ws = SpreadsheetApp.getActiveSpreadsheet();
let ss=ws.getSheetByName("Data");
let startingRange = ss.getDataRange();
let data =startingRange.getValues();
data.shift();
data.sort((a,b)=>a[0]-b[0]) //ascemding
//data.sort((a,b)=>b[3]-a[3]) //decreasing
let formulaRange = ss.getRange(2,4,data.length)
let formulas=formulaRange.getFormulas()
let finalRange=ss.getRange(2,1,data.length,data[0].length)
finalRange.setValues(data)
formulaRange.setFormulas(formulas)
}