优化执行时间

时间:2017-11-14 15:28:51

标签: google-apps-script

我有一个循环,它从不同的文件中获取值,并以所需的格式将它们全部放在一个文件中。我的代码工作,读取2个文件需要4分钟的问题。我的代码中的以下片段是我认为花费时间最长的代码片段。我的脚本循环非常相似。我的问题是,是否有人可以帮助我重写代码,因此运行时间更短。我认为有一种方法可以使用我不知道如何的数组。感谢。

for(var row = 16; row<=28;row++) { // Nested Loop checks the individual SKUs and gets the information
        //Variable "row" is for the SAF File, Not the Recap

          if( fileSheet.getRange("A"+row).isBlank()) {  //If file is out of info

            break; // break out of loop
            Logger.log("This code should never be executed")
          }

          if( !fileSheet.getRange("A"+row).isBlank()) { 

           var hValue = fileSheet.getRange("D2").getValue() ; // gets the distributor for the SAF
           recap.getRange("C"+(recap.getLastRow())).offset(1,0).setValue(hValue) ; //offset is needed to put info in the row after the last row

            var lRow = recap.getLastRow() ; // last row of the ----!RECAP!---- After Offset

           hValue = fileSheet.getRange("A"+row).getValue() ; //gets the SKU
           recap.getRange("E"+lRow).setValue(hValue) ;


           hValue = fileSheet.getRange("D"+row).getValue() ; //gets the quantity
           recap.getRange("H"+lRow).setValue(hValue) ;

           hValue = fileSheet.getRange("E"+row).getValue() ; //gets the price
           recap.getRange("G"+lRow).setValue(hValue) ;

           hValue = fileSheet.getRange("H"+row).getValue() ; // gets the 
                                                                discount%

           recap.getRange("K"+lRow).setValue(hValue) ;

            hValue = fileSheet.getRange("A2").getValue() ; //gets  the date

            recap.getRange("P"+lRow).setValue(hValue) ;

            hValue = currentFile.getUrl() //gets the url of the SAF
            recap.getRange("R"+lRow).setValue(hValue) ;

0 个答案:

没有答案
相关问题