- I think that when only cell values are copied, I would like to propose to use Spreadsheet service. But in your question, I understood you wanted to use `copyTo`. In this case, I would like to propose to use Sheets API.
- From your question, I suppose that "filter" in your situation is the basic filter.
const srcSheetName = "onglet_import"; // Please set the source sheet name.
const dstSheetName = "onglet_donnees"; // Please set the destination sheet name.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const srcSheet = ss.getSheetByName(srcSheetName);
const srcSheetId = ss.getSheetByName(srcSheetName).getSheetId();
const dstSheetId = ss.getSheetByName(dstSheetName).getSheetId();
const reqs = [];
let dstRow = 0;
for (let r = 1; r <= srcSheet.getLastRow(); r++) {
if (!srcSheet.isRowHiddenByFilter(r)) {
reqs.push({copyPaste: {
source: {sheetId: srcSheetId, startRowIndex: r - 1, endRowIndex: r, startColumnIndex: 0},
destination: {sheetId: dstSheetId, startRowIndex: dstRow, endRowIndex: dstRow + 1, startColumnIndex: 0}
}});
dstRow++;
}
}
Sheets.Spreadsheets.batchUpdate({requests: reqs}, ss.getId());
- When above script is run, the visible rows are copied from the source sheet to the destination sheet.