Drive.Files.update causes unwanted page refresh in Google Sheets (but not Docs/Slides)

Hi everyone,

I’m working on an Apps Script add-on that updates the currently open file with base64 data from an API call using Drive.Files.update().

The Issue:

  • Works perfectly in Google Docs and Slides - content updates without refresh

  • In Google Sheets, it causes the entire page to reload, closing my add-on sidebar

function insertXlsxToSheet(base64Data) {
  try {
    const currentId = SpreadsheetApp.getActiveSpreadsheet().getId();
    const decoded = Utilities.base64Decode(base64Data);
    const blob = Utilities.newBlob(
      decoded,
      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
      "upload.xlsx"
    );

    const updatedFile = Drive.Files.update(
      {
        mimeType: "application/vnd.google-apps.spreadsheet",
      },
      currentId,
      blob
    );

    return {
      success: true,
      message: "✅ XLSX content successfully replaced.",
      fileUrl: `https://docs.google.com/spreadsheets/d/${updatedFile.id}/edit`,
    };
  } catch (error) {
    return { success: false, message: error.message };
  }
}

Question: Is there a way to update the active spreadsheet content via Drive API without triggering a page refresh? Or is there an alternative approach using SpreadsheetApp that could achieve the same result?

Any insights would be greatly appreciated!

Short answer: not reliably.

In Sheets, calling Drive.Files.update() on the currently open spreadsheet to replace its underlying content (especially by uploading an XLSX blob) forces the editor to re-sync the document state, which triggers a full page reload and closes the add-on sidebar. This is expected behavior and you generally can’t prevent it while mutating the active file via Drive API.

Recommended approach (no page refresh):

  1. Upload/convert the XLSX into a temporary Google Sheet (separate file ID)
  2. Copy values/formulas/formats from the temporary sheet into the active spreadsheet using SpreadsheetApp
  3. Delete the temporary file when done

High-level pattern:

  • Create temp spreadsheet from the XLSX (Drive API / DriveApp)
  • Read temp data (SpreadsheetApp.openById(tempId))
  • Write into the active spreadsheet (setValues, setFormulas, copyTo, etc.)
  • Clean up (Drive.Files.remove / DriveApp.getFileById(tempId).setTrashed(true))

This keeps the active editor stable because you’re not replacing the active file binary—only updating its cells via SpreadsheetApp.