gsheets.googlesheets.updatevalues
Home > @runlightyear/gsheets > GoogleSheets > updateValues
GoogleSheets.updateValues() method
This API is in beta and may contain contain bugs. Can be used in production with caution.
Sets values in a range of a spreadsheet.
Signature:updateValues(props: UpdateValuesProps): Promise<UpdateValuesResponse>;
Parameters
Parameter | Type | Description |
---|---|---|
props | UpdateValuesProps |
Promise<UpdateValuesResponse>
Example 1
Update a row
import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";
function randomNumber() {
return Math.floor(Math.random() * 10);
}
defineAction({
name: "updateRow",
title: "Update Row",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});
const response = await gsheets.updateValues({
spreadsheetId: variables.spreadsheetId!,
range: "1:1",
valueInputOption: "RAW",
valueRange: {
range: "1:1",
majorDimension: "ROWS",
values: [[randomNumber(), randomNumber(), randomNumber()]],
},
});
console.log("Response: ", response.data);
},
});
Example 2
Update a column
import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";
function randomNumber() {
return Math.floor(Math.random() * 10);
}
defineAction({
name: "updateColumn",
title: "Update Column",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});
const response = await gsheets.updateValues({
spreadsheetId: variables.spreadsheetId!,
range: "A:A",
valueInputOption: "RAW",
valueRange: {
range: "A:A",
majorDimension: "COLUMNS",
values: [[randomNumber(), randomNumber(), randomNumber()]],
},
});
console.log("Response: ", response.data);
},
});
Example 3
Update rows and columns
import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";
defineAction({
name: "updateRowsAndColumns",
title: "Update Rows and Columns",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});
const response = await gsheets.updateValues({
spreadsheetId: variables.spreadsheetId!,
range: "A1:C3",
valueInputOption: "RAW",
valueRange: {
range: "A1:C3",
majorDimension: "ROWS",
values: [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
],
},
});
console.log("Response: ", response.data);
},
});