Google sheet Apps script | Tự động Sắp xếp dữ liệu theo cột bất kỳ Auto Sort by Column
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ế:
- Google sheet webapp | CRUD FORM – ĐIỀN THÔNG TIN TỪ FORM VÀO TEMPLATE GOOGLE DOC, KÈM HÌNH ẢNH
- Google sheet webapp | Dropdown phụ thuộc – Truy xuất Spreadsheet và các Sheet phụ thuộc từ Folder
- Tạo hóa đơn trên Google sheet – Gửi email đính kèm hóa đơn pdf – Quản lý url hóa đơn trên danh sách
- Google sheet Ứng dụng theo dõi đơn hàng – Danh sách sản phẩm mua, trạng thái đơn hàng
- Tip on Ms Word Hướng dẫn tạo ngắt trang, xóa ngắt trang đơn lẽ hoặc toàn bộ ngắt trang trên file doc
- Google sheet | Generate QR Codes – Mã hóa nội dung Cell – Thêm hình ở giữa mã QR code
- Google sheet App Script | Tạo custom menu – Xóa tất cả dòng Rỗng trên vùng dữ liệu Nhanh chống
- Google Script Web | From upload file – Kiểm tra trùng lặp – Ghi đè hoặc Tạo phiên bản mới cho file
- Google Script Web | Trang Tìm kiếm nhiều điều kiên riêng lẽ hoặc hết hợp – Print, Xuất file PDF
- Hướng dẫn kiểm tra Bàn phím, Tháo và thay bàn phím mới cho Dell Inspirion 15 3000 series
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)
}