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