![](/img/trans.png)
[英]Transfer Data from one sheet to another and deleting old data in google sheets
[英]Importing data with formula from another google sheet and deleting original data
我正在使用以下腳本從另一個 Google Sheet 導入數據,但它沒有引入我需要的公式。
我已經嘗試過ImportRange
但這似乎只是同步了兩張工作表,我需要刪除原始工作表(工作表 1)中的數據,但這也會在我購買的工作表(主工作表)中刪除它。
有沒有另一種方法來實現這一點?
function Copy() {
var sss = SpreadsheetApp.openById('Sheet 1 ID');
var ss = sss.getSheetByName('results');
var range = ss.getRange('2:688');
var data = range.getValues();
var tss = SpreadsheetApp.openById('Master Sheet ID');
var ts = tss.getSheetByName('results');
ts.getRange(ts.getLastRow() + 1, 1, data.length, data[0].length).setValues(
data
);
var sheet = SpreadsheetApp.openById('Sheet 1 ID').getSheetByName('Roger');
ss.getRange('2:688').clearContent();
}
getValues()
檢索公式range#getFormulas
和range#getValues
並混合這兩個數組以創建一個公式和值數組,以便稍后使用setValues()
。 var data = range.getValues();
data = range.getFormulas().map(function(e, i) {//i=index of row(e)
return e.map(function(f, j) {//j = index of column(f)
return f === "" ? data[i][j] : f;
});
});
或者
var req = {
ranges: 'results!2:688',
valueRenderOption: 'FORMULA', //get formulas with values
};
var r = Sheets.Spreadsheets.Values.batchGet('Sheet 1 ID', req);
data = r.valueRanges[0].values;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.