我有一个伪代码,但还不能编码



谢谢您,对不起,我提前没有经验的问题。因此,我想制作一个代码,我知道我想做什么,我只是不知道如何编程。我需要的是:

函数genpre()
1.-删除范围Presupuesto!A12:C42
2.-复制范围imp!a2:presupuesto!a12中的imp!c33值:presupuesto!c42(imp单元格是公式,我只想复制值)
3.-在Presupuesto!A12:A42中仅显示A列中使用的行 4.-转到表presupuesto(我执行此功能后,我想最终进入presupuesto
结束通用

此功能将由同一电子表格的另一张表中的按钮运行。

到目前为止,我有:

function GenPre() {  
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetbyname(Presupuesto);
//next step is to select and delete the content of the range on the sheet
}

我知道我要问的很多,我只是找不到太多选择定义的单元格...我真的不知道该如何编程。

感谢一堆!

编辑

所以,我开始对K4K4SH1回答的内容进行调整,并得到了此内容(并阅读有关给定单元格上包含" X"的其他帖子的其他帖子):

function GenPre() {
  var sheetp = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Presupuesto') //name a variable to the sheet where we're pasting information
  var sheetc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Imp')         //name a variable to the sheet frome where we're copying information
  sheetp.getRange('a12:c41').clearContent()                                        //delete all values in the range where we're copying
  sheetc.getRange('A2:C31').copyValuesToRange(sheetp,1,3,12,41);                    //copy from source range to destination range
  sheetp.showRows(12,41);                                                          //make sure all rows in the destination range are shown
  for( i=12 ; i<=41 ; i++) { 
       if (sheetp.getRange('A'+i).getValue() == '') { // status == ''
         sheetp.hideRows(i);
       } 
   }
}

te脚本正在运行它应该如何运行,但是现在,我希望它运行更快(当它看起来并不那么沉重时需要12秒钟的运行),并且是否有将视图切换到SheetP的功能?谢谢大家!


您要我们做所有的工作:)让我们从您的代码开始:方法.getSheetByName(shName)接受字符串作为参数,因此您应该将其更改为
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Presupuesto');。请注意,JavaScript对病例敏感,因此.getSheetbyname.getSheetByName()不同。根据表格类参考,请使用sheet.getRange()获取您的范围对象。查看范围类参考:要清除包括格式的范围内容使用.clear(),以清除剩余格式完整的内容使用.clearContent()。隐藏未使用的行尝试:

function hideRows(sheetName, column) {
    var s = SpreadsheetApp.getActive().getSheetByName(sheetName);
    s.showRows(1, s.getMaxRows());
    s.getRange(column)
        .getValues()
        .forEach(function (r, i) {
            if (r[0] == '') {s.hideRows(i + 1);}
        });
}
// hideRows('Presupuesto', 'A12:A42');

最新更新