我试图在电子表格的某些动态部分执行复制粘贴(仅值)操作,以便准备将其导出到excel。我正在尝试通过数组和嵌套的for循环使用copyTo方法。
// here i define all the sheets
var activeSS, mikumimSheet,rankSheet, conveSheet, srcSheet, clkImpSheet, gaSheet, salesSheet, lndpageSheet;
activeSS = SpreadsheetApp.getActiveSpreadsheet();
mikumimSheet = activeSS.getSheetByName('עותק של מיקומים בגוגל');
rankSheet = activeSS.getSheetByName("מיקומים בגוגל");
conveSheet = activeSS.getSheetByName("המרות");
srcSheet = activeSS.getSheetByName("מקורות תנועה");
clkImpSheet = activeSS.getSheetByName("חשיפות והקלקות");
gaSheet = activeSS.getSheetByName("Google Ads");
salesSheet = activeSS.getSheetByName("מכירות באתר");
lndpageSheet = activeSS.getSheetByName("דפי נחיתה");
// here some code inject data to cells all over the spread sheet
// setHeaders();
// here i store all the cells i need to copy paste and run the copyTo method
function copyPasteReplace() {
var cells = [
[srcSheet, "A2:G2", "B53:C53"],
[salesSheet, "A1:F1"],
[clkImpSheet, "A1:E1"],
[rankSheet, "A1:E1", "C11:E11"],
[conveSheet, "A1:G1", "A30:H30", "O11:O17"],
[lndpageSheet, "A1:D1"],
[gaSheet, "A1:F1"]
];
for (var i = 0; i < cells.length; i++) {
for (var n = 1; n < cells[i].length; n++) {
cells[i][0].getRange(cells[i][n]).copyTo(cells[i][0].getRange(cells[i][n]), {
contentsOnly: true
});
}
}
}
// this is the order of execution
function onOpennn() {
setHeaders();
copyPasteReplace();
}
我希望工作表中的所有值都先注入,然后以值形式粘贴(没有公式)。 实际上发生了什么事,因为这些单元只是被清空了。
答案 0 :(得分:1)
我发现我的代码有问题。事实证明,我不得不在ranges数组中添加工作表名称,就像这样:
UITableViewController
我不知道原因,因为工作表已经定义, 但这是修复它的原因。