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:
- 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
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();
};