Apps Script setValues() fails only on an existing Google Sheets tab with “Service Spreadsheets failed while accessing document with id”

Hello,

I am experiencing a reproducible Google Apps Script / Google Sheets issue with this error:

Service Spreadsheets failed while accessing document with id [REDACTED]

I have a spreadsheet-bound Apps Script that processes several source sheets in memory. It generates 419 data rows and 141 columns, then writes 420 rows including the header row.

The write operation is essentially:

const datos = [cabeceras].concat(filas);
sheet.getRange(1, 1, datos.length, 141).setValues(datos);

What is unusual is that the exact same data and the exact same setValues() operation behave differently depending on the destination worksheet:

  1. Existing worksheet “consolidado viajes”: setValues() fails repeatedly with the service error.
  2. A copy of that worksheet: the same error occurs.
  3. A completely new blank worksheet in the SAME spreadsheet: the same 420 x 141 write succeeds.
  4. A worksheet in a DIFFERENT spreadsheet (“Consolidado Bitacora”): the same 420 x 141 write also succeeds.

The data-processing stage itself always succeeds:

  • 419 data rows are generated in memory.
  • 141 output columns are generated.
  • The data matrix is valid and rectangular.
  • No spreadsheet filter was present during the final test.

The failing execution stopped immediately after:

W10: writing 420 rows x 141 columns

and never reached the next log statement.

I then created a completely new diagnostic worksheet in the same spreadsheet and ran the exact same write. It completed successfully:

Intentando escribir: 420 filas x 141 columnas
*** ESCRITURA EN HOJA DE PRUEBA OK ***
*** FLUSH OK ***

I also duplicated the problematic worksheet, and the duplicated worksheet failed in the same way.

Finally, I created a completely new blank production worksheet and changed the script to use that worksheet as the destination. The full consolidation process then completed successfully, including the write to the auditor worksheet.

So the current evidence suggests that the problem is related to the internal state or structure of the original worksheet, or to a Sheets backend issue triggered by that worksheet state. I cannot identify which specific worksheet property causes it.

Environment:

  • Google Sheets
  • Google Apps Script / V8
  • Spreadsheet-bound script
  • Windows / Chrome
  • SpreadsheetApp
  • LockService
  • AppSheet is connected to some of the source sheets, but the consolidation output is used mainly for visualization by auditors.

Questions:

  1. Is there a known Google Sheets / Apps Script issue where setValues() can consistently fail on an existing worksheet while the same operation succeeds on a newly created worksheet in the same spreadsheet?
  2. Is there a recommended way to diagnose or repair a worksheet that consistently produces this error?
  3. Could there be worksheet-level metadata or internal state that survives duplication and causes this behavior?

I can provide sanitized execution logs and a minimal reproduction script if needed.

Thank you.

One thing I would test is whether the issue is tied to the worksheet itself rather than the size or contents of the data. Since the exact same 420 × 141 setValues() works on a newly created sheet in the same spreadsheet, that is a pretty strong signal.

You could compare the failing and working sheets for things such as merged cells, protected ranges, named ranges, hidden rows/columns, filters, conditional formatting, data validation, tables, or unusual formatting. The fact that duplicating the problematic sheet also reproduces the error is especially interesting, because it suggests some sheet-level state may be getting copied.

Another useful diagnostic would be to create a new blank sheet and gradually reproduce the important properties of the original sheet, testing setValues() after each change. That could help isolate the specific feature or metadata triggering the failure. If none of those reproduce it, I would suspect a Sheets backend/internal-state issue rather than a problem with the data matrix itself.