从一个工作表复制查询函数的结果,并将其追加到不同文件中另一个工作表的末尾



是否可以从谷歌工作表中选择查询(=query(Dom,"select * WHERE G is not null")(函数的结果并将其附加到另一个谷歌工作表的末尾?

错误:"找不到方法 openById(字符串,字符串(。

我基本上在两个不同的位置有两个Google表格,它们都是平面文件格式。

function Dom() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getSheetByName('Dom_Sum').showSheet()
.activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Dom_Sum'), true);

var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getCurrentCell().offset(1, 0).activate();
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
currentCell.activateAsCurrentCell();


var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];
var destination = SpreadsheetApp.openById("17J0_YiUANs9CZNmq2tqqvwjdAT2P8IVcx3NYljhqTFk","Master_Db!A1");
spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.UP).activate();
spreadsheet.getCurrentCell().offset(1, 0).activate();
sheet.copyTo(destination);


spreadsheet.getSheetByName('Dom_Sum').hideSheet()

var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getSheetByName('Indent Form_Dom').showSheet()
.activate();
spreadsheet.getRangeList(['C4:D9', 'A12:M112']).activate()
.clear({contentsOnly: true, skipFilteredRows: true});
spreadsheet.getRange('C4').activate();

};

当 openById(( 只允许一个参数时,你向它提供了两个参数。

另外,如果我理解正确,您只想将(非空(数据从 G 列复制到另一张纸。

如果是这样,您可以尝试以下操作:

function Dom() {
var origin_sheet = SpreadsheetApp.getActive().getSheetByName('Dom_Sum');
var firstRow = 1;
var firstCol = 7;
var numRows = origin_sheet.getLastRow();
var numCols = 1;
var origin_values = origin_sheet.getRange(firstRow, firstCol, numRows, numCols).getValues();
var dest_values = [];
for(var i = 0; i < origin_values.length; i++) {
if(origin_values[i][0] != '') {
dest_values.push(origin_values[i]);
}
}
var dest_id = "1ZGq7L7bvF1INuDgZxhHnVsihkYkYubmncSAE5uC-Pq4";
var dest_sheet = SpreadsheetApp.openById(dest_id).getSheetByName("Master_Db");
var numRowsDest = dest_values.length;
var dest_range = dest_sheet.getRange(1, 1, numRowsDest, 1);
dest_range.setValues(dest_values);
}

如果这不是你想要的,我很抱歉。

最新更新