Google Spreadsheet freezes when done running App S

2020-07-24 04:00发布

问题:

I have an app script attached to my Google Spreadsheet. There is a function that does a bunch of stuff withing the spreadsheet. Here is what it does.

  1. Create a new Sheet
  2. Set column header for new sheet
  3. Copy data in new sheet
  4. Set Formulas
  5. Delete Extra columns
  6. Delete Extra rows
  7. Add A row in an existing sheet(Sheet 1)
  8. Add a column in an existing sheet(Sheet 2)
  9. Add Formula in new column in Sheet 2
  10. Edit Value in an existing sheet's cell (Sheet 3).

After these 10 steps are complete, the spreadsheet works normally but after 10-15 secs, the sheet will freeze. To get it to work, I need to refresh the page.

I experimented and I found out that if I eliminate Step 6 i.e "Delete Extra rows", the freeze behavior is eliminated. Why does it freeze on this particular step? How do I fix this? I cannot not delete extra rows. Here is the exact piece of code where it freezes.

var unwanted = newAssignmentSheet.getMaxRows() - (parseInt(i) + 6);
newAssignmentSheet.deleteRows(i+7, unwanted); //FREEZES HERE

Point to note :

If I implement Step 6 in isolation, the Spreadsheet does not freeze.

回答1:

I discovered that if you leave at least one empty row below the last contingent cell, the spreadsheet will not become unresponsive.