Giáo án link (giaoanlink) chia sẻ đến các bạn project Google sheet App Script Copy and paste value from One Spreadsheet to Other spreadsheet. Trong project này chúng ta sẽ thực hiện việc copy giá trị của vùng dữ liệu của Spreadsheet này đến paste vào sheet của Spreadsheet khác. Việc thực thi lệnh có thể thông qua Menu custom hoặc các bạn tạo các triger đáp ứng nhu cầu.
Xem thêm các bài học excel ứng dụng khác:
- Biến Google Sheets thành Dashboard “Viễn Tưởng” phong cách Cyberpunk
- Google appscript | Hệ thống tìm thông tin và nhập liệu 2 Form-Tự động truy vấn và upload nhiều files
- Google sheet Webapp|Giáo viên chủ nhiệm quản lý điểm, thống kê xếp hạng chia sẻ cho phụ huynh
- Google sheet Webapp | Bản nâng cấp Tìm và Load Thông tin sinh viên có Hình ảnh và Bảng kết quả thi
- Google webapp | Form tìm, hiển thị kết quả học tập nhiều môn và in phiếu kết quả
- Danh mục các Bài học Google sheet Apps script Cơ bản
- Bản Nâng cấp Hệ thống hóa đơn Phân quyền Quản lý khách Quản lý sản phẩm Quản lý hóa đơn
- Tạo webapp import và update dữ liệu từ Excel lên Google sheet có Load bảng Table lên nền tảng web
- Google sheet, appscript và webapp – Giải pháp thu hoạc phí toàn diện
- Quản Lý Học Phí Bằng Google Apps Script: Form CRUD, Tìm Kiếm, In Phiếu Thu và Tự Động Tính Toán
Mã apps scrip trong project:
function onOpen(){
let ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Copy to other spreadsheet','runsies')
.addToUi();
}
function runsies() {
importRange(
"1NlK7e8m8HHRxG6noCH0SrlEWA33uO9OBypSAW4ULuaM", //Source Spreadsheet ID
"Source!A1:D", // Source Range
"1Gr90_SuotOFZNQTzs5VyNHPKop3ajpkrAMEf0Ncp7sA", // Target Spreadsheet ID
"Target!B2" // Target Begin Range
);
};
/**
* sourceID - ID of Source Spreadsheet
* sourceRange - Contain Sheet tab and Range of data
* targetID - ID of Target Spreadsheet
* targetRangeStart - cell address to start pasting the data area into targetsheet
*/
function importRange(sourceID, sourceRange, targetID, targetRangeStart){
// Get the source range values
const sourceSS = SpreadsheetApp.openById(sourceID);
const sourceRng = sourceSS.getRange(sourceRange)
const sourceVals = sourceRng.getValues();
// Get the target sheet and cell location.
const targetSS = SpreadsheetApp.openById(targetID);
const targetStartRange = targetSS.getRange(targetRangeStart);
const targetSheet = targetStartRange.getSheet();
// Clear previous entries.
targetSheet.clear();
// Get the full data range to paste from start range.
const targetRange = targetSheet.getRange(
targetStartRange.getRow(),
targetStartRange.getColumn(),
sourceVals.length,
sourceVals[0].length
);
// Paste in the values.
targetRange.setValues(sourceVals);
SpreadsheetApp.flush();
};
