ID
Composables

useGSheetWrite

Mutate spreadsheet data using append, update, and clear functions.

The useGSheetWrite composable returns functions to append, update, and clear cell values in Google Sheets.

Writing operations require either appscript or service-account authentication mode.

Signature

function useGSheetWrite(globalOptions?: { sheet?: string }): {
  append: (range: string | GSheetWriteOptions, values?: any[][]) => Promise<any>
  update: (range: string | GSheetWriteOptions, values?: any[][]) => Promise<any>
  clear: (range: string | GSheetWriteOptions) => Promise<any>
}

Functions

append(range, values)

Appends new rows of data after the last row of the specified range.

update(range, values)

Overwrites existing cells in the specified range.

clear(range)

Clears cell contents from the specified range.

Basic Example

components/AddForm.vue
<script setup lang="ts">
const { append, update, clear } = useGSheetWrite({ sheet: 'submissions' })
const isSaving = ref(false)

const handleAppend = async () => {
  isSaving.value = true
  try {
    await append('A1:C1', [
      ['SUB-101', 'Jane Doe', 'jane@example.com']
    ])
    alert('Row added!')
  }
  finally {
    isSaving.value = false
  }
}

const handleUpdate = async () => {
  await update('B2:C2', [
    ['Jane Smith', 'jane.smith@example.com']
  ])
}

const handleClear = async () => {
  await clear('A5:C5')
}
</script>

<template>
  <div class="actions">
    <button :disabled="isSaving" @click="handleAppend">
      Append Row
    </button>
    <button @click="handleUpdate">
      Update Row 2
    </button>
    <button @click="handleClear">
      Clear Row 5
    </button>
  </div>
</template>