Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the bwp-ext domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/giaoanli/public_html/wp-includes/functions.php on line 6121
Google sheet Apps Script | Tạo Folder và File từ Giá trị trên Google sheet » Tài liệu miễn phí cho Giáo viên, học sinh.
Site icon Tài liệu miễn phí cho Giáo viên, học sinh.

Google sheet Apps Script | Tạo Folder và File từ Giá trị trên Google sheet

Google sheet Apps Script – Tạo Folder và File từ Giá trị trên Google sheet. Trong ví dụ này, Spreadsheet có bảng dữ liệu gồm cột tên phim, năm sản xuất và mô tả. Chúng ta sẽ tạo các folder trên Onedrive có tên là Tên phim và trong folder đó chứa File document có nội dung là Mô tả phim. Tác vụ sẽ quét tất cả các dòng thông qua custom menu. Bạn xem thêm trong video hướng dẫn bên dưới.

Bài học excel ứng dụng:

Mã code.gs

//https://giaoan.link chia se tai lieu
function onOpen(){
  let ui = SpreadsheetApp.getUi();
    ui.createMenu("LẤY TÊN PHIM & MÔ TẢ")
    .addItem('Thực hiện','myFunction')
    .addToUi();
}

function myFunction() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getActiveSheet();
  const lastRow = sheet.getLastRow();
  const rootFolder = DriveApp.getFolderById("1q9qKA_47NmWa3m1TFrgIP8f_ix3gPu20");

    for(var i=2;i<=lastRow;i++){
      let title = sheet.getRange(i,1).getValue();
      let description = sheet.getRange(i,3).getValue();
        if(title != "title"){
          let folderID = rootFolder.createFolder(title).getId();
          let folder = DriveApp.getFolderById(folderID);
          let docID = DocumentApp.create(title).getId();
          let document = DocumentApp.openById(docID);
          let paragraph = document.getBody().appendParagraph(description);
          DriveApp.getFileById(docID).moveTo(folder);
        }
    }
}

Video hướng dẫn

Exit mobile version