Giaoan.link chia sẻ đến các bạn về Google sheet, apps script. Trong project này sẽ thực hiện Insert images from folder to spreadsheet – chèn hình ảnh từ folder vào cell của spreadsheet. Điều kiện là folder chứa hình ảnh phải được share dưới dạng “anyone with the link”. Dưới đây là code tham khảo và video hướng dẫn cụ thể.
Các bài tập excel ứng dụng:
- 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 trên file “Code.gs”
var ws=SpreadsheetApp.getActiveSpreadsheet();
var ss = ws.getActiveSheet();
function onOpen(){
var ui = SpreadsheetApp.getUi();
ui.createMenu('LẤY HÌNH ẢNH')
.addItem('Xem hình ảnh','previewAllImages')
.addToUi();
};
function previewAllImages(){
var folderId = Browser.inputBox('Nhập ID của folder',Browser.Buttons.OK_CANCEL);
if(folderId===""){
Browser.msgBox('Bạn chưa nhập ID folder');
return;
}
getFolderTree(folderId);
};
function getFolderTree(folderId){
//let target = ws.getSheetByName('Sheet1');
//target.getDataRange().clearContent();
ss.appendRow(["Name","Created Date","Updated Date","Size","URL","Download","Description","Image"]);
var folder = DriveApp.getFolderById(folderId);
var filecontents=folder.getFiles();
var cnt=0;
var file;
while(filecontents.hasNext){
var file = filecontents.next();
cnt++;
data = [
file.getName(),
file.getLastUpdated(),
file.getLastUpdated(),
file.getSize(),
file.getUrl(),
"https://docs.google.com/uc?export=download&id=" + file.getId(),
file.getDescription(),
"=image(\"https://docs.google.com/uc?id=" + file.getId() + "\")",
];
ss.appendRow(data);
};
}