Apps script google sheet là ngôn ngữ lập trình của google được kế thừa từ ngôn ngữ gốc là Java Script, được tích hợp vào các ứng dụng của google như  Calendar (Lịch), Contacts (Danh bạ), Documents (Tài liệu), Drive (Lưu trữ đám mây), Forms (Biểu mẫu), Gmail (Email), Group (Nhóm)...

Học Apps Script Google Sheet toàn tập


Apps Script Google sheet là gì?

App Script Google Script - là 1 ngôn ngữ lập trình dựa trên ngôn ngữ lập trình gốc là Javascript.  Với công cụ này bạn có thể lập trình để thao tác, can thiệp trực tiếp đến các dịch vụ của Google, giúp tự động hóa đơn các quá trình làm thủ công.


Apps Script Google có thể làm được những gì?

    Thêm menu, dialogs, và thanh sidebar tùy chỉnh vào Google Docs, Sheets và Forms.
    Viết các hàm mở rộng hoặc các macros cho Google Sheets.
    Xuất bản Web Apps - độc lập hoặc tích hợp vào trang web của Google Sites.
    Tương tác với các dịch vụ khác của Google, bao gồm AdSense, Analytics, Lịch, Drive, Gmail và Bản đồ.
    Xây dựng các tiện ích bổ sung để mở rộng Google Docs, Sheets, Slides và Forms và xuất bản chúng lên cửa hàng Add-on.
    Chuyển đổi ứng dụng Android thành một tiện ích bổ sung Android để ứng dụng có thể trao đổi dữ liệu với Google Doc hoặc Sheet của người dùng trên thiết bị di động.
    Xây dựng Chat bot cho Hangout chat


Hiện tại Apps Scripts Google Script có thể lập trình để thao tác với hầu hết các dịch vụ của Google:

    Calendar (Lịch)
    Contacts (Danh bạ)
    Documents (Tài liệu)
    Drive (Lưu trữ đám mây)
    Forms (Biểu mẫu)
    Gmail (Email)
    Group (Nhóm)
    Language (Dịch)
    Maps (Bản đồ)
    Sites (Trang web)
    Slides (Trình chiếu)
    SpreadSheet (Bảng tính).

Sau đây mình gởi đến các bạn các đoạn code Apps Scripts Google Script cơ bản nhé:


1. Khai báo biến
với Apps script google sheet
-   Biến kiễu chữ:
  var tenbien = Giá trị;
 Ví dụ:
 var hoten="Tran Van A";
Logger.log(hoten);

- Biến kiễu số
var so=10;
so=so+1;
Logger.log(so);

2. Tạo biến Sheet với Apps script google sheet


var sheet = SpreadsheetApp.getActiveSheet(); //lấy đối tượng sheet đưa vào biến để xử lý
  spreadsheet.getRange('B5').activate();   // Kích hoạt vị trí chọn
  spreadsheet.getCurrentCell().setValue('4'); // Gán giá trị cho ô đang chọn
  Logger.log('Noi dung in'); //Ghi nội dung log, chỉ xem được tại trình soạn lệnh

// HÀM IN NỘI DUNG RA LOG

3. Vòng lặp
  var sheet = SpreadsheetApp.getActiveSheet(); // lấy sheet hiện tại được vào biến
  var data = sheet.getDataRange().getValues(); //lấy giá trị hàng (trong gồm các ô) đưa vào biến mãng
  for (var i = 0; i < data.length; i++) {  // lặp
    Logger.log('Product name: ' + data[i][0]); //in ra
    Logger.log('Product number: ' + data[i][1]);
  }

4. Chèn hàng vào google sheet với Apps script google sheet

 var sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow(['Cotton Sweatshirt XL', 'css004']);
 

5. Set font cho ô với Apps script google sheet

 var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var cell = sheet.getRange('B2:C2');
  cell.setFontStyle('italic');
 

 

6. Set DataValidation cho ô với Apps script google sheet
// Set a rule for the cell B4 to be a number between 1 and 100.
  var cell = SpreadsheetApp.getActive().getRange('B4');
  var rule = SpreadsheetApp.newDataValidation()
     .requireNumberBetween(1, 100)
     .setAllowInvalid(false)
     .setHelpText('Number must be between 1 and 100.')
     .build();
  cell.setDataValidation(rule);

//=============================
7. Hiển thị thông báo với Apps script google sheet:
var ui = SpreadsheetApp.getUi(); // Same variations.

  var result = ui.alert(
     'Please confirm',
     'Are you sure you want to continue?',
      ui.ButtonSet.YES_NO);

  // Process the user's response.
  if (result == ui.Button.YES) {
    // User clicked "Yes".
    ui.alert('Confirmation received.');
  } else {
    // User clicked "No" or X in the title bar.
    ui.alert('Permission denied.');
  }
 

8. Hiển thị hộp thoại có ô nhập liệu với Apps script google sheet

var ui = SpreadsheetApp.getUi(); // Same variations.

  var result = ui.prompt(
      'Let\'s get to know each other!',
      'Please enter your name:',
      ui.ButtonSet.OK_CANCEL);

  // Process the user's response.
  var button = result.getSelectedButton();
  var text = result.getResponseText();
  if (button == ui.Button.OK) {
    // User clicked "OK".
    ui.alert('Your name is ' + text + '.');
  } else if (button == ui.Button.CANCEL) {
    // User clicked "Cancel".
    ui.alert('I didn\'t get your name.');
  } else if (button == ui.Button.CLOSE) {
    // User clicked X in the title bar.
    ui.alert('You closed the dialog.');
  }

 

9. HÀM GỞI MAIL với Apps script google sheet
function SendAnEmail() {
  // gán email nhận
  var email = 'xxxxx@yahoo.com'
  // Tiều đề gởi mail
  var subject = 'This is my first script!';
  // Nội dung gởi mail
  var body = 'Hello, world!';
  // Send an email
  GmailApp.sendEmail(email, subject, body);
}

Đăng ký khóa học Apps script google sheet theo số điện thoại 0935999617
Thời gian học 1 tháng, 1 tuần 2 buổi, 1 buổi (1,5 giờ)


 

 

 

Cảm ơn đã xem, đã có 1,164 lượt xem.
Thông báo:

phần mềm bán hàng

Học lập trình khác
Tag tìm kiếm:

apps script google sheet

Thông tin liên hệ

Zalo 0935 999617

Zalo 0972 13 14 19