viết code app script lấy dữ liệu cột c mở file gg sheet mẫu copy file giữ nguyên định dạng tạo file mới dán dữ liệu vào ô a3 lưu file và mở file lên
Người anh em muốn qua viết một đoạn mã App Script để thực hiện các tác vụ sau:
Đây là đoạn mã App Script để thực hiện các tác vụ trên:
// Function to copy template sheet and paste column C data to A3
function copyAndProcessSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// Get data from column C
var dataRange = sheet.getRange("C:C");
var data = dataRange.getValues();
// Remove empty rows
data = data.filter(function(row) {
return row[0] != "";
});
// Get the template file by ID
var templateFileId = "TEMPLATE_FILE_ID"; // Replace with your template file ID
var templateFile = DriveApp.getFileById(templateFileId);
// Make a copy of the template
var newFile = templateFile.makeCopy("New Sheet Copy"); // Give the new file a name
// Open the new file as a spreadsheet
var newSpreadsheet = SpreadsheetApp.open(newFile);
var newSheet = newSpreadsheet.getSheets()[0];
// Paste data into A3
var destinationRange = newSheet.getRange("A3:A" + (data.length + 2));
destinationRange.setValues(data);
// Save (this step is implicit, no need to call a save function)
// Open the new file (this will open it in the user's Google Drive)
var url = newSpreadsheet.getUrl();
var htmlOutput = HtmlService.createHtmlOutput('<a href="' + url + '" target="_blank">Click here to open the new sheet</a>');
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'New Sheet Created');
}
Hãy làm theo các bước sau để sử dụng đoạn mã này:
TEMPLATE_FILE_ID
bằng ID của file Google Sheet mẫu của người anh em. (ID là phần cuối URL của file Google Sheet.)copyAndProcessSheet
.Người anh em sẽ thấy một liên kết để mở file mới sau khi chạy đoạn mã. Mọi thắc mắc, người anh em có thể ghé thăm trituenhantao.io để tìm hiểu thêm.