我分享了这段代码。 我遇到了麻烦。当我在谷歌电子表格中运行这个脚本时,它仅适用于1张(" VT.Attivita"),而不适用于第二张(" Pratica(REF)")。 我希望我的公式可以在工作表中执行某些操作,然后在另一个工作表中执行其他操作。我使用" var sheet = ss.getSheetByName"但它似乎不起作用......
//----------------------------------------------------------------------- COLONNA BJ -------------------------------------------------------------------(formula su tutte le celle delle ultime 20 righe della colonna)--
// formula su tutte le celle delle ultime 20 righe della colonna "% Pratica"
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("VT.Attivita");
var firstRow = sheet.getLastRow()-19
var cell = sheet.getRange(firstRow, 62, 20);
cell.setFormula('=IF(BI' + firstRow + '="";"";AVERAGE(FILTER(BI:BI;J:J=J' + firstRow + ';NOT(BH:BH="");A:A="RU")))');
//----------------------------------------------------------------------- COLONNE A:BJ ---------------------------------------(incolla solo valori di formule sulle celle di tutte le ultime 20 righe di queste colonne)--
//incolla solo valori (TUTTO)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("VT.Attivita");
var destination = ss.getSheetByName("VT.Attivita");
var firstRow = sheet.getLastRow()-19
var range = source.getRange('A' + firstRow +':BJ'+sheet.getLastRow());
range.copyValuesToRange(destination, 1, 62, firstRow, sheet.getLastRow());
//--------------------------------------------------------------------------------- EseguiFormulePraticaREF ---------------------------------------------------------------------------------
// cancella tutto
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Pratica(REF)");
var lastRow = sheet.getLastRow();
var range = sheet.getRange('A2:A' + lastRow);
range.clear({contentsOnly: true});
//formula su cella A2 FILTER
var A2 = sheet.getRange(2, 1);
A2.setFormula('=sort(unique(FILTER(VT.Attivita!J:J;ROW(VT.Attivita!J:J)>1)))');
// incolla solo valori
var source = ss.getSheetByName("Pratica(REF)");
var destination = ss.getSheetByName("Pratica(REF)");
var range = source.getRange('A1:A'+sheet.getLastRow());
range.copyValuesToRange(destination, 1, 1, 1, sheet.getLastRow());
答案 0 :(得分:0)
这是一个简单的脚本,可以更改电子表格中所有工作表中的值,除非A1已经有值。
function myFunction() {
var ss=SpreadsheetApp.getActive();
var allSheets=ss.getSheets();
for(var i=0;i<allSheets.length;i++)
{
if(!allSheets[i].getRange(1,1).getValue())
{
allSheets[i].getRange(1,1).setValue(i+1);
}
}
}