Tự động điền dữ liệu từ Google sheet sang Mẫu trên Google Doc
Trong project google sheet, google doc và apps script này, mình chia sẽ là “Tự động điền dữ liệu từ Google sheet sang Mẫu trên Google Doc” – Autofill google Doc template from google sheet. Nếu như bạn đã từng sử dụng mergmail trên MS Word thì ở đây nó cũng tương tự nhưng chúng ta thực hiện trên dịch vụ đám mây của Google. Bạn xem video hướng dẫn bên dưới và code mâu app script.
Các project khác bạn có thể xem thêm:
- Apsscript Radio Button và Input – Sự phụ thuộc của input vào Radio button
- Bạn sử dụng zalo và bị báo đầy ổ đĩa,phải làm sao
- Google sheet Webapp Login form Tocken quản lý phiên đăng nhập, gửi mail lấy lại thông tin đăng nhập
- Chuyển bảng dữ liệu từ file PDF vào Excel
- Google sheet Apps script Hệ thống duyệt hồ sơ sinh viên – Form nhập liệu, Login duyêt, gửi mail
- Tool VBA Form Excel xử lí chuỗi tạo folder hàng loạt theo danh sách
- Google sheet webapp | Quản lý quán Cà phê – Phân quyền- Quét QR chấm công- Quản lý nhân viên-Báo cáo
- VBA Excel Xây dựng hàm chuyển chuỗi có dấu thành không dấu, khoản trắng thành dấu –
- Google sheet Webapp | Lấy dữ liệu trên Sheet hiển thị dạng Bảng có phân trang trùy chọn trên website
- Web App Script | Trang trắc nghiệm online hỗ trợ hình ảnh, lưu file kết quả – Form nhập bộ câu hỏi
Mã “Code.gs”
function onOpen(){
const ui = SpreadsheetApp.getUi();
ui.createMenu('AutoFill Docs')
.addItem("Create New Docs", "createNewGoogleDocs")
.addToUi();
}
function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById('1Z_bSOXrT7BswSVae9NDcCTsUQO9Aw4WEGEmQlFZjsj4');
const destinationFolder = DriveApp.getFolderById('12A-67fVuIm-ckK2SgY0WbvHqK_Xm6j5-')
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data')
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index) {
if (index === 0) return;
if (row[5]) return;
const copy = googleDocTemplate.makeCopy(`Thư mời Ông (bà) ${row[0]} tham dự Hội nghị`, destinationFolder)
const doc = DocumentApp.openById(copy.getId())
const body = doc.getBody();
//const friendlyDate = new Date(row[3]).toLocaleDateString();
body.replaceText('{{Hovaten}}', row[0]);
body.replaceText('{{Diachi}}', row[1]);
body.replaceText('{{Donvi}}', row[2]);
body.replaceText('{{Dienthoai}}', row[3]);
body.replaceText('{{Email}}', row[4]);
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index +1, 6).setValue(url)
})
}