.getValue () занимает слишком много времени в скрипте Google - PullRequest
1 голос
/ 12 ноября 2019

У меня есть несколько ячеек, которые требуют много времени, чтобы получить значение. У меня часто getValues(), это намного быстрее, всего несколько десятков миллисекунд. Это проблема с ячейкой или просто медленная функция? В чем причина такой медлительности? В моем скрипте есть еще много вызовов getValue(), но ни один из них не занимает более 400 миллисекунд. Много раз я запускаю, только эти 2 ячейки очень медленно получают значение.

//Original issue
[19-11-11 19:05:16:980 ICT] SpreadsheetApp.Sheet.getRange([A13]) [0 seconds]
[19-11-11 19:05:19:286 ICT] SpreadsheetApp.Range.getValue() [2.306 seconds]
[19-11-11 19:05:12:373 ICT] SpreadsheetApp.Sheet.getRange([F1]) [0 seconds]
[19-11-11 19:05:16:326 ICT] SpreadsheetApp.Range.getValues() [3.952 seconds]

Это код

//This function put data from a key sheet into a database sheet. 
function enterTransDatabase_()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetLocation = ss.getSheetByName('DefaultValues');

//This get the location of data in the key sheet and database field and match them
var dBField = convert2SingleArray(sheetLocation.getRange('A26:A54').getValues());
var keySummary = convert2SingleArray(sheetLocation.getRange('B26:B54').getValues());
var keyDataLocation = convert2SingleArray(sheetLocation.getRange('C26:C54').getValues());
var numberFormat = convert2SingleArray(sheetLocation.getRange('D26:D54').getValues());

var sheetKey = ss.getSheetByName('Data_entry');
var sheetDB = ss.getSheetByName('Trans_DB_Temp');
var lastRow = sheetDB.getLastRow();
var transLines = Math.max(sheetKey.getRange('J10').getValue(),1);
var nextSTT = ss.getSheetByName('DefaultValues').getRange('G2').getValue();
var beginTransRow; 
var maxSearchRow = 20;
var searchColumn = 7;
var formatArray = []
var dataRange = []


//Create numbering for data entries
var sttColumn = []
for (var i1 = 0; i1<transLines;i1++)
{
  sttColumn.push([nextSTT + i1])
}
sheetDB.getRange(lastRow+1, 1,transLines,1).setValues(sttColumn);

for (var iR=0; iR<transLines;iR++)
{
var copyArray = []
formatArray.push(numberFormat)
for (var iC =0; iC<dBField.length;iC++)
{
  if(keySummary[iC]==1)
  {
    if (keyDataLocation[iC] == 'D10')
    {copyArray[iC] = sheetKey.getRange(keyDataLocation[iC]).getDisplayValue();}
    else
    {copyArray[iC] = sheetKey.getRange(keyDataLocation[iC]).getValue();}
  }
  else if (keySummary[iC]==0)
  {
    copyArray[iC] = sheetKey.getRange(14 + iR,keyDataLocation[iC]).getValue();
  }
  else if (keySummary[iC]===2)     
  {
    if (dBField[iC]==='Time used')   
    {copyArray[iC] = Math.round((sheetKey.getRange('V14').getValue() - sheetKey.getRange('V9').getValue())/1000/transLines)}
    else if (dBField[iC]==='IsCurrent')   
    {copyArray[iC] = 1}
    else if (dBField[iC]==='STT dòng')   
    {copyArray[iC] = iR + 1}
    else if (dBField[iC]==='ID dòng')   
    {copyArray[iC] = (10000 + copyArray[26]*1)*1000 + copyArray[27]}
  }
}
dataRange.push(copyArray)
}
sheetDB.getRange(lastRow+1, 2, transLines, dBField.length).setNumberFormats(formatArray)
sheetDB.getRange(lastRow+1, 2, transLines, dBField.length).setValues(dataRange)
sheetDB.getRange(lastRow+1, 34, transLines, 1).setValue('Cell G6 in Default')
KeyUpdate()
return true;
}

Это журнал выполнения.

[19-11-11 19:05:10:830 ICT] SpreadsheetApp.getActiveRange() [0 seconds]
[19-11-11 19:05:10:830 ICT] SpreadsheetApp.Range.getRow() [0 seconds]
[19-11-11 19:05:10:830 ICT] SpreadsheetApp.Range.getLastRow() [0 seconds]
[19-11-11 19:05:10:830 ICT] SpreadsheetApp.Range.getColumn() [0 seconds]
[19-11-11 19:05:10:830 ICT] SpreadsheetApp.Range.getLastColumn() [0 seconds]
[19-11-11 19:05:10:830 ICT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-11-11 19:05:10:832 ICT] Starting execution
[19-11-11 19:05:10:845 ICT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-11-11 19:05:10:846 ICT] SpreadsheetApp.Spreadsheet.getActiveSheet() [0 seconds]
[19-11-11 19:05:10:903 ICT] SpreadsheetApp.Sheet.getName() [0.056 seconds]
[19-11-11 19:05:10:904 ICT] SpreadsheetApp.Spreadsheet.getActiveSheet() [0 seconds]
[19-11-11 19:05:10:904 ICT] SpreadsheetApp.Range.getColumn() [0 seconds]
[19-11-11 19:05:10:904 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:904 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:904 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:905 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:10:906 ICT] SpreadsheetApp.Range.setValue([false]) [0 seconds]
[19-11-11 19:05:10:907 ICT] SpreadsheetApp.Sheet.getRange([J10]) [0 seconds]
[19-11-11 19:05:11:193 ICT] SpreadsheetApp.Range.getValue() [0.285 seconds]
[19-11-11 19:05:11:194 ICT] SpreadsheetApp.Sheet.getRange([D12]) [0 seconds]
[19-11-11 19:05:11:300 ICT] SpreadsheetApp.Range.getValue() [0.105 seconds]
[19-11-11 19:05:11:302 ICT] Logger.log([Start checking, []]) [0 seconds]
[19-11-11 19:05:11:303 ICT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-11-11 19:05:11:303 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([Data_entry]) [0 seconds]
[19-11-11 19:05:11:304 ICT] SpreadsheetApp.Sheet.getRange([J10]) [0 seconds]
[19-11-11 19:05:11:304 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:305 ICT] Logger.log([5.0, []]) [0 seconds]
[19-11-11 19:05:11:305 ICT] SpreadsheetApp.Sheet.getRange([14, 4]) [0 seconds]
[19-11-11 19:05:11:305 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:11:306 ICT] SpreadsheetApp.Sheet.getRange([14, 5]) [0 seconds]
[19-11-11 19:05:11:306 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:11:307 ICT] SpreadsheetApp.Sheet.getRange([14, 6]) [0 seconds]
[19-11-11 19:05:11:307 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:11:307 ICT] SpreadsheetApp.Sheet.getRange([14, 7]) [0 seconds]
[19-11-11 19:05:11:308 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:11:308 ICT] SpreadsheetApp.Sheet.getRange([14, 8]) [0 seconds]
[19-11-11 19:05:11:308 ICT] SpreadsheetApp.Range.getA1Notation() [0 seconds]
[19-11-11 19:05:11:309 ICT] SpreadsheetApp.Sheet.getRange([D7]) [0 seconds]
[19-11-11 19:05:11:441 ICT] SpreadsheetApp.Range.isBlank() [0.131 seconds]
[19-11-11 19:05:11:441 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:442 ICT] SpreadsheetApp.Sheet.getRange([D8]) [0 seconds]
[19-11-11 19:05:11:442 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:442 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:443 ICT] SpreadsheetApp.Sheet.getRange([D9]) [0 seconds]
[19-11-11 19:05:11:444 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:444 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:445 ICT] SpreadsheetApp.Sheet.getRange([D10]) [0 seconds]
[19-11-11 19:05:11:445 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:445 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:446 ICT] SpreadsheetApp.Sheet.getRange([D11]) [0 seconds]
[19-11-11 19:05:11:446 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:446 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:447 ICT] SpreadsheetApp.Sheet.getRange([D12]) [0 seconds]
[19-11-11 19:05:11:447 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:447 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:447 ICT] SpreadsheetApp.Sheet.getRange([J7]) [0 seconds]
[19-11-11 19:05:11:448 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:448 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:448 ICT] SpreadsheetApp.Sheet.getRange([D14]) [0 seconds]
[19-11-11 19:05:11:448 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:449 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:449 ICT] SpreadsheetApp.Sheet.getRange([E14]) [0 seconds]
[19-11-11 19:05:11:449 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:449 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:450 ICT] SpreadsheetApp.Sheet.getRange([F14]) [0 seconds]
[19-11-11 19:05:11:450 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:450 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:451 ICT] SpreadsheetApp.Sheet.getRange([G14]) [0 seconds]
[19-11-11 19:05:11:451 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:451 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:452 ICT] SpreadsheetApp.Sheet.getRange([H14]) [0 seconds]
[19-11-11 19:05:11:452 ICT] SpreadsheetApp.Range.isBlank() [0 seconds]
[19-11-11 19:05:11:452 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:452 ICT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-11-11 19:05:11:453 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([DefaultValues]) [0 seconds]
[19-11-11 19:05:11:454 ICT] SpreadsheetApp.Sheet.getRange([A26:A54]) [0 seconds]
[19-11-11 19:05:11:596 ICT] SpreadsheetApp.Range.getValues() [0.142 seconds]
[19-11-11 19:05:11:598 ICT] SpreadsheetApp.Sheet.getRange([B26:B54]) [0 seconds]
[19-11-11 19:05:11:598 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:11:599 ICT] SpreadsheetApp.Sheet.getRange([C26:C54]) [0 seconds]
[19-11-11 19:05:11:599 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:11:600 ICT] SpreadsheetApp.Sheet.getRange([D26:D54]) [0 seconds]
[19-11-11 19:05:11:601 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:11:602 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([Data_entry]) [0 seconds]
[19-11-11 19:05:11:602 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([Trans_DB_Temp]) [0 seconds]
[19-11-11 19:05:11:785 ICT] SpreadsheetApp.Sheet.getLastRow() [0.182 seconds]
[19-11-11 19:05:11:786 ICT] SpreadsheetApp.Sheet.getRange([J10]) [0 seconds]
[19-11-11 19:05:11:787 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:11:787 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([DefaultValues]) [0 seconds]
[19-11-11 19:05:11:788 ICT] SpreadsheetApp.Sheet.getRange([G2]) [0 seconds]
[19-11-11 19:05:11:906 ICT] SpreadsheetApp.Range.getValue() [0.117 seconds]
[19-11-11 19:05:11:907 ICT] SpreadsheetApp.Sheet.getRange([1, 7]) [0 seconds]
[19-11-11 19:05:12:089 ICT] SpreadsheetApp.Range.getValue() [0.181 seconds]
[19-11-11 19:05:12:090 ICT] SpreadsheetApp.Sheet.getRange([2, 7]) [0 seconds]
[19-11-11 19:05:12:090 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:091 ICT] SpreadsheetApp.Sheet.getRange([3, 7]) [0 seconds]
[19-11-11 19:05:12:091 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:092 ICT] SpreadsheetApp.Sheet.getRange([4, 7]) [0 seconds]
[19-11-11 19:05:12:092 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:092 ICT] SpreadsheetApp.Sheet.getRange([5, 7]) [0 seconds]
[19-11-11 19:05:12:092 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:093 ICT] SpreadsheetApp.Sheet.getRange([6, 7]) [0 seconds]
[19-11-11 19:05:12:093 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:094 ICT] SpreadsheetApp.Sheet.getRange([7, 7]) [0 seconds]
[19-11-11 19:05:12:094 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:094 ICT] SpreadsheetApp.Sheet.getRange([8, 7]) [0 seconds]
[19-11-11 19:05:12:094 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:095 ICT] SpreadsheetApp.Sheet.getRange([9, 7]) [0 seconds]
[19-11-11 19:05:12:095 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:096 ICT] SpreadsheetApp.Sheet.getRange([10, 7]) [0 seconds]
[19-11-11 19:05:12:096 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:096 ICT] SpreadsheetApp.Sheet.getRange([11, 7]) [0 seconds]
[19-11-11 19:05:12:096 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:097 ICT] SpreadsheetApp.Sheet.getRange([12, 7]) [0 seconds]
[19-11-11 19:05:12:097 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:098 ICT] SpreadsheetApp.Sheet.getRange([13, 7]) [0 seconds]
[19-11-11 19:05:12:098 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:12:098 ICT] SpreadsheetApp.Range.getRow() [0 seconds]
[19-11-11 19:05:12:098 ICT] SpreadsheetApp.Sheet.getRange([750, 1, 1, 1]) [0 seconds]
[19-11-11 19:05:12:372 ICT] SpreadsheetApp.Range.setValues([[[750.0]]]) [0.273 seconds]
[19-11-11 19:05:12:373 ICT] SpreadsheetApp.Sheet.getRange([F1]) [0 seconds]
[19-11-11 19:05:16:326 ICT] SpreadsheetApp.Range.getValues() [3.952 seconds]
[19-11-11 19:05:16:326 ICT] SpreadsheetApp.Sheet.getRange([D10]) [0 seconds]
[19-11-11 19:05:16:486 ICT] SpreadsheetApp.Range.getDisplayValue() [0.159 seconds]
[19-11-11 19:05:16:487 ICT] SpreadsheetApp.Sheet.getRange([J7]) [0 seconds]
[19-11-11 19:05:16:487 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:488 ICT] SpreadsheetApp.Sheet.getRange([D8]) [0 seconds]
[19-11-11 19:05:16:645 ICT] SpreadsheetApp.Range.getValues() [0.157 seconds]
[19-11-11 19:05:16:647 ICT] SpreadsheetApp.Sheet.getRange([D7]) [0 seconds]
[19-11-11 19:05:16:782 ICT] SpreadsheetApp.Range.getValues() [0.135 seconds]
[19-11-11 19:05:16:784 ICT] SpreadsheetApp.Sheet.getRange([D11]) [0 seconds]
[19-11-11 19:05:16:784 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:785 ICT] SpreadsheetApp.Sheet.getRange([D12]) [0 seconds]
[19-11-11 19:05:16:785 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:786 ICT] SpreadsheetApp.Sheet.getRange([D9]) [0 seconds]
[19-11-11 19:05:16:786 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:787 ICT] SpreadsheetApp.Sheet.getRange([A101]) [0 seconds]
[19-11-11 19:05:16:961 ICT] SpreadsheetApp.Range.getValues() [0.173 seconds]
[19-11-11 19:05:16:962 ICT] SpreadsheetApp.Sheet.getRange([14, 4]) [0 seconds]
[19-11-11 19:05:16:962 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:963 ICT] SpreadsheetApp.Sheet.getRange([14, 12]) [0 seconds]
[19-11-11 19:05:16:963 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:964 ICT] SpreadsheetApp.Sheet.getRange([14, 5]) [0 seconds]
[19-11-11 19:05:16:964 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:964 ICT] SpreadsheetApp.Sheet.getRange([14, 6]) [0 seconds]
[19-11-11 19:05:16:964 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:965 ICT] SpreadsheetApp.Sheet.getRange([14, 7]) [0 seconds]
[19-11-11 19:05:16:965 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:965 ICT] SpreadsheetApp.Sheet.getRange([14, 9]) [0 seconds]
[19-11-11 19:05:16:966 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:966 ICT] SpreadsheetApp.Sheet.getRange([14, 8]) [0 seconds]
[19-11-11 19:05:16:966 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:967 ICT] SpreadsheetApp.Sheet.getRange([A101]) [0 seconds]
[19-11-11 19:05:16:967 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:967 ICT] SpreadsheetApp.Sheet.getRange([14, 10]) [0 seconds]
[19-11-11 19:05:16:968 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:968 ICT] SpreadsheetApp.Sheet.getRange([J11]) [0 seconds]
[19-11-11 19:05:16:968 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:969 ICT] SpreadsheetApp.Sheet.getRange([J12]) [0 seconds]
[19-11-11 19:05:16:969 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:969 ICT] SpreadsheetApp.Sheet.getRange([Q1]) [0 seconds]
[19-11-11 19:05:16:969 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:970 ICT] SpreadsheetApp.Sheet.getRange([V1]) [0 seconds]
[19-11-11 19:05:16:970 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:971 ICT] SpreadsheetApp.Sheet.getRange([V2]) [0 seconds]
[19-11-11 19:05:16:971 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:971 ICT] SpreadsheetApp.Sheet.getRange([V3]) [0 seconds]
[19-11-11 19:05:16:971 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:972 ICT] SpreadsheetApp.Sheet.getRange([V14]) [0 seconds]
[19-11-11 19:05:16:972 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:973 ICT] SpreadsheetApp.Sheet.getRange([V9]) [0 seconds]
[19-11-11 19:05:16:973 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:16:973 ICT] SpreadsheetApp.Sheet.getRange([J1]) [0 seconds]
[19-11-11 19:05:16:973 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:16:974 ICT] SpreadsheetApp.Sheet.getRange([750, 2, 1, 29]) [0 seconds]
[19-11-11 19:05:16:975 ICT] SpreadsheetApp.Range.setNumberFormats([[[@, dd/mm/yyyy, @, @, @, @, #,##0, @, @, @, @, @, #,##0.00, #,##0.00, #,##0.00, #0%, @, #,##0, #,##0, #,##0, @, @, @, dd/mm/yyyy hh:mm:ss, #,##0, #,##0, #,##0, #,##0, #,##0]]]) [0 seconds]
[19-11-11 19:05:16:975 ICT] SpreadsheetApp.Sheet.getRange([750, 2, 1, 29]) [0 seconds]
[19-11-11 19:05:16:976 ICT] SpreadsheetApp.Range.setValues([[[Gokids Việt Nam, 15/8/19, HĐ VAT, Hoa Tươi- Quà Tặng& Trái Cây Yến Nhi, 0314804996, 03CB/18P, 26230.0, Mua, , Hoa tươi, , bó, 1.0, 700000.0, 700000.0, K, , 700000.0, 700000.0, 700000.0, 910_IBS_new...) [0 seconds]
[19-11-11 19:05:16:977 ICT] SpreadsheetApp.Sheet.getRange([750, 34, 1, 1]) [0 seconds]
[19-11-11 19:05:16:977 ICT] SpreadsheetApp.Range.setValue([Cell G6 in Default]) [0 seconds]
[19-11-11 19:05:16:977 ICT] SpreadsheetApp.getActive() [0 seconds]
[19-11-11 19:05:16:978 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([Data_entry]) [0 seconds]
[19-11-11 19:05:16:978 ICT] SpreadsheetApp.Sheet.getRange([V3]) [0 seconds]
[19-11-11 19:05:16:979 ICT] SpreadsheetApp.Range.setValue([Mon Nov 11 19:05:16 GMT+07:00 2019]) [0 seconds]
[19-11-11 19:05:16:980 ICT] SpreadsheetApp.Sheet.getRange([A13]) [0 seconds]
[19-11-11 19:05:19:286 ICT] SpreadsheetApp.Range.getValue() [2.306 seconds]
[19-11-11 19:05:19:287 ICT] Logger.log([Starting cleaning up sheet, []]) [0 seconds]
[19-11-11 19:05:19:288 ICT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-11-11 19:05:19:289 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([DefaultValues]) [0 seconds]
[19-11-11 19:05:19:289 ICT] SpreadsheetApp.Sheet.getRange([A2:A22]) [0 seconds]
[19-11-11 19:05:19:390 ICT] SpreadsheetApp.Range.getValues() [0.1 seconds]
[19-11-11 19:05:19:391 ICT] SpreadsheetApp.Sheet.getRange([B2:B22]) [0 seconds]
[19-11-11 19:05:19:391 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:19:392 ICT] SpreadsheetApp.Sheet.getRange([C2:C22]) [0 seconds]
[19-11-11 19:05:19:393 ICT] SpreadsheetApp.Range.getValues() [0 seconds]
[19-11-11 19:05:19:394 ICT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-11-11 19:05:19:395 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([Data_entry]) [0 seconds]
[19-11-11 19:05:19:395 ICT] SpreadsheetApp.Sheet.getRange([K1]) [0 seconds]
[19-11-11 19:05:19:522 ICT] SpreadsheetApp.Range.getValue() [0.126 seconds]
[19-11-11 19:05:19:523 ICT] SpreadsheetApp.Sheet.getRange([V9]) [0 seconds]
[19-11-11 19:05:19:525 ICT] SpreadsheetApp.Sheet.getRange([V14]) [0 seconds]
[19-11-11 19:05:19:525 ICT] SpreadsheetApp.Range.getValue() [0 seconds]
[19-11-11 19:05:19:526 ICT] SpreadsheetApp.Range.setValue([Mon Nov 11 19:05:18 GMT+07:00 2019]) [0 seconds]
[19-11-11 19:05:19:526 ICT] Logger.log([started cleaning , []]) [0 seconds]
[19-11-11 19:05:19:527 ICT] SpreadsheetApp.Sheet.getRange([D8:D11]) [0 seconds]
[19-11-11 19:05:19:528 ICT] SpreadsheetApp.Range.setNumberFormat([@]) [0 seconds]
[19-11-11 19:05:19:528 ICT] SpreadsheetApp.Sheet.getRange([L14:L100]) [0 seconds]
[19-11-11 19:05:19:720 ICT] SpreadsheetApp.Range.clear([{contentsOnly=true}]) [0.191 seconds]
[19-11-11 19:05:19:721 ICT] SpreadsheetApp.Sheet.getRange([D1:E1]) [0 seconds]
[19-11-11 19:05:19:948 ICT] SpreadsheetApp.Range.clear([{contentsOnly=true}]) [0.226 seconds]
[19-11-11 19:05:19:949 ICT] SpreadsheetApp.Sheet.getRange([A1]) [0 seconds]
[19-11-11 19:05:20:024 ICT] SpreadsheetApp.Range.setValue([false]) [0.074 seconds]
[19-11-11 19:05:20:025 ICT] SpreadsheetApp.Sheet.getRange([D7]) [0 seconds]
[19-11-11 19:05:20:026 ICT] SpreadsheetApp.Range.setValue([=iferror(VLOOKUP($E$1;$A$2:$B$6;2;0);"Phải điền")]) [0 seconds]
[19-11-11 19:05:20:026 ICT] SpreadsheetApp.Sheet.getRange([D8]) [0 seconds]
[19-11-11 19:05:20:027 ICT] SpreadsheetApp.Range.setValue([=if(or(D7="Phải điền";NOT(ISFORMULA(D7)));"Phải điền";if(isnumber(E1);index(D2:D6;E1;1);IFERROR(vlookup(D7; MST_DB_All!D2:F;2;0); iferror(getAddrFromMST(D7;0);"Phải điền"))))]) [0 seconds]
[19-11-11 19:05:20:028 ICT] SpreadsheetApp.Sheet.getRange([D9]) [0 seconds]
[19-11-11 19:05:20:028 ICT] SpreadsheetApp.Range.setValue([=IF(MID(Q1;6;1)="S";"Bán";"Mua")]) [0 seconds]
[19-11-11 19:05:20:029 ICT] SpreadsheetApp.Sheet.getRange([D10:D12]) [0 seconds]
[19-11-11 19:05:20:255 ICT] SpreadsheetApp.Range.clear([{contentsOnly=true}]) [0.225 seconds]
[19-11-11 19:05:20:256 ICT] SpreadsheetApp.Sheet.getRange([I14]) [0 seconds]
[19-11-11 19:05:20:320 ICT] SpreadsheetApp.Range.setValue([=if(or(D14="";$J$7="Tờ khai");"";G14*F14)]) [0.064 seconds]
[19-11-11 19:05:20:321 ICT] SpreadsheetApp.Sheet.getRange([J14]) [0 seconds]
[19-11-11 19:05:20:322 ICT] SpreadsheetApp.Range.setValue([=if(D14="";"";(iferror(--H14;0)+1)*if($J$7="Tờ khai";G14;I14))]) [0 seconds]
[19-11-11 19:05:20:323 ICT] SpreadsheetApp.Sheet.getRange([J7]) [0 seconds]
[19-11-11 19:05:20:323 ICT] SpreadsheetApp.Range.setValue([=VLOOKUP(mid(Q1;5;3);DefaultValues!$M$1:$N$5;2;0)]) [0 seconds]
[19-11-11 19:05:20:324 ICT] SpreadsheetApp.Sheet.getRange([J8]) [0 seconds]
[19-11-11 19:05:20:325 ICT] SpreadsheetApp.Range.setValue([false]) [0 seconds]
[19-11-11 19:05:20:325 ICT] SpreadsheetApp.Sheet.getRange([A14:H100]) [0 seconds]
[19-11-11 19:05:20:761 ICT] SpreadsheetApp.Range.clear([{contentsOnly=true}]) [0.436 seconds]
[19-11-11 19:05:20:763 ICT] SpreadsheetApp.Sheet.getRange([I15:K100]) [0 seconds]
[19-11-11 19:05:20:914 ICT] SpreadsheetApp.Range.clear([{contentsOnly=true}]) [0.151 seconds]
[19-11-11 19:05:20:915 ICT] SpreadsheetApp.Sheet.getRange([K14]) [0 seconds]
[19-11-11 19:05:20:979 ICT] SpreadsheetApp.Range.setValue([false]) [0.064 seconds]
[19-11-11 19:05:20:980 ICT] SpreadsheetApp.Sheet.getRange([D14]) [0 seconds]
[19-11-11 19:05:20:981 ICT] SpreadsheetApp.Range.setValue([=if(and(left($D$2;5)="Không";$J$8<>"");"Phải điền";if(isblank(C14);""; INDEX($D$2:$D$6;C14;1)))]) [0 seconds]
[19-11-11 19:05:20:981 ICT] SpreadsheetApp.Sheet.getRange([V10]) [0 seconds]
[19-11-11 19:05:20:982 ICT] SpreadsheetApp.Sheet.getRange([A14]) [0 seconds]
[19-11-11 19:05:20:982 ICT] SpreadsheetApp.Range.copyTo([Range, PASTE_FORMULA, false]) [0 seconds]
[19-11-11 19:05:20:983 ICT] SpreadsheetApp.Sheet.getRange([J1]) [0 seconds]
[19-11-11 19:05:21:347 ICT] SpreadsheetApp.Range.getValue() [0.363 seconds]
[19-11-11 19:05:21:348 ICT] SpreadsheetApp.Sheet.getRange([J1]) [0 seconds]
[19-11-11 19:05:21:349 ICT] SpreadsheetApp.Range.setValue([377.0]) [0 seconds]
[19-11-11 19:05:21:350 ICT] SpreadsheetApp.Sheet.getRange([F1]) [0 seconds]
[19-11-11 19:05:21:350 ICT] SpreadsheetApp.Range.setValue([=vlookup(VLOOKUP($J$1;File_list!$A$2:$F;2;0);ClientDB!$C$2:$D;2;0)]) [0 seconds]
[19-11-11 19:05:21:351 ICT] SpreadsheetApp.Sheet.getRange([B2]) [0 seconds]
[19-11-11 19:05:21:351 ICT] SpreadsheetApp.Range.setValue([=if(V12="";"";if(V11="SP"; iferror(query(Goods_DB_All!A2:D;" Select B where lower(D) contains '"&$V$12&"' and B contains '"&$F$1&"' limit 5");"Không có kết quả");iferror(query(MST_DB_All!A2:I;" Selec...) [0 seconds]
[19-11-11 19:05:21:352 ICT] SpreadsheetApp.Sheet.getRange([D2]) [0 seconds]
[19-11-11 19:05:21:352 ICT] SpreadsheetApp.Range.setValue([=if(V12="";"";if(V11="SP"; iferror(query(Goods_DB_All!A2:D;" Select C where lower(D) contains '"&$V$12&"' and B contains '"&$F$1&"' limit 5");"Không có kết quả trong cơ sở dữ liệu, hãy nhập mới");ife...) [0 seconds]
[19-11-11 19:05:21:353 ICT] SpreadsheetApp.Sheet.getRange([17, 2, 100, 11]) [0 seconds]
[19-11-11 19:05:21:354 ICT] SpreadsheetApp.Range.setBackground([null]) [0 seconds]
[19-11-11 19:05:21:354 ICT] SpreadsheetApp.Sheet.getRange([B7:J12]) [0 seconds]
[19-11-11 19:05:21:355 ICT] SpreadsheetApp.Range.setBorder([false, false, false, false, false, false]) [0 seconds]
[19-11-11 19:05:21:355 ICT] SpreadsheetApp.Sheet.getRange([B14:L100]) [0 seconds]
[19-11-11 19:05:21:356 ICT] SpreadsheetApp.Range.setBorder([false, false, false, false, false, false]) [0 seconds]
[19-11-11 19:05:21:356 ICT] SpreadsheetApp.Sheet.getRange([D14:D100]) [0 seconds]
[19-11-11 19:05:26:086 ICT] SpreadsheetApp.Range.getValues() [4.729 seconds]
[19-11-11 19:05:26:087 ICT] SpreadsheetApp.Sheet.getRange([B14:L16]) [0 seconds]
[19-11-11 19:05:26:089 ICT] SpreadsheetApp.Range.setBorder([true, true, true, true, false, false]) [0 seconds]
[19-11-11 19:05:26:089 ICT] SpreadsheetApp.Sheet.getRange([B7:J12]) [0 seconds]
[19-11-11 19:05:26:090 ICT] SpreadsheetApp.Range.setBorder([true, true, true, true, false, false]) [0 seconds]
[19-11-11 19:05:26:091 ICT] Logger.log([Done resetting cells, []]) [0 seconds]
[19-11-11 19:05:26:091 ICT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-11-11 19:05:26:092 ICT] SpreadsheetApp.Spreadsheet.getSheetByName([Data_entry]) [0 seconds]
[19-11-11 19:05:26:093 ICT] SpreadsheetApp.Sheet.getRange([V1]) [0 seconds]
[19-11-11 19:05:26:407 ICT] SpreadsheetApp.Range.getValue() [0.313 seconds]
[19-11-11 19:05:26:559 ICT] SpreadsheetApp.Sheet.getImages() [0.152 seconds]
[19-11-11 19:05:31:400 ICT] SpreadsheetApp.OverGridImage.replace([https://drive.google.com/a/tsas.vn/uc?id=1knpfbX7k7TSDi2hQZ4lTheLBJ641Xvce&export=download]) [4.84 seconds]
[19-11-11 19:05:31:401 ICT] Logger.log([Replacing done, []]) [0 seconds]
[19-11-11 19:05:33:020 ICT] SpreadsheetApp.OverGridImage.getHeight() [0.118 seconds]
[19-11-11 19:05:33:021 ICT] SpreadsheetApp.OverGridImage.getWidth() [0 seconds]
[19-11-11 19:05:33:022 ICT] SpreadsheetApp.Sheet.getRange([O1]) [0 seconds]
[19-11-11 19:05:33:112 ICT] SpreadsheetApp.Range.getValue() [0.089 seconds]
[19-11-11 19:05:33:113 ICT] SpreadsheetApp.OverGridImage.setWidth([600]) [0 seconds]
[19-11-11 19:05:33:490 ICT] SpreadsheetApp.OverGridImage.setHeight([849]) [0.377 seconds]
[19-11-11 19:05:33:491 ICT] Logger.log([resize done, []]) [0 seconds]
[19-11-11 19:05:33:492 ICT] SpreadsheetApp.Sheet.getRange([1, 4]) [0 seconds]
[19-11-11 19:05:33:492 ICT] SpreadsheetApp.Range.activate() [0 seconds]
[19-11-11 19:05:33:493 ICT] Logger.log([Clean sheet done, []]) [0 seconds]
[19-11-11 19:05:33:920 ICT] Execution succeeded [22.649 seconds total runtime]

1 Ответ

1 голос
/ 12 ноября 2019

После многих испытаний я нашел причину медлительности. Оказывается, что всякий раз, когда вы переключаете лист с другого листа, который вы просто setValue на getValue, это занимает много времени. Из моих экспериментов только setValue будет составлять «заданный лист как текущий», и только getValue будет составлять «лист переключения». Другие функции, такие как getRange, getSheetByName, isBlank (необходимо перепроверить), getLastRow не имеют такого же эффекта. Не имеет значения, загружен лист в память или нет. Не имеет значения, является ли функция getValue или getValues. Другие действия, кажется, не имеют значения. Например,

var sheetA = ss.getSheetByName('A');
var sheetB = ss.getSheetByName('B');
var cell1 = sheetA.getRange(1,1)
cell1.setValue('ABC')//"current sheet" is now sheet A
var something = sheetA.getRange(1,1).getValue()//Same sheet as last setValue=>Fast
[most other operations doesn't involve getValue in another sheet] //Fast
var cell2 = sheetB.getRange(1,1)//getRange from other sheet is not affected =>fast
cell1.setValue('CDE')//setValue is not "switching sheet" => fast 
cell1.setValue('GHK')//"current sheet" is now sheet A
var value2 = cell2.getValue() //<= getValue in sheet B. Slow, at least 2-3000 milliseconds.
  • Так что, если это возможно, и вы заботитесь о секундах времени реакции, вам следует свести к минимуму лист переключения, когда setValue и getValue
  • Кроме того, если выработа между 3 листами в операции, гарантируется, что операция займет не менее 4-6 секунд.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...