July
BBuildShip
•Created by July on 4/11/2024 in #💬・general
July - Hey, the google sheet add row doesnt see...
also doesnt require cell number
12 replies
BBuildShip
•Created by July on 4/11/2024 in #💬・general
July - Hey, the google sheet add row doesnt see...
now updates with a single row ["1","2"..]
12 replies
BBuildShip
•Created by July on 4/11/2024 in #💬・general
July - Hey, the google sheet add row doesnt see...
I made a quick update so it adds a new row instead of replacing the existing range
function getTotalSubarrays(data, sheetName) {
const values = data.values;
if (Array.isArray(values)) {
// const numberOfSubarrays = values.filter(row => row.length > 0).length;
const numberOfSubarrays = values.length;
return
${sheetName}!A${numberOfSubarrays+1}
;
}
// Handle the case where "values" is not an array
return ${sheetName}!A1
; // Adjust to your specific default range or handle accordingly
}
async function batchAppendGoogleSheet({
spreadsheetId,
dataArray,
sheetName
}, {
auth
}) {
const { access_token } = await auth.getToken();
// Fetch the current values from the Google Sheet
const getSheet = await fetch(https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${sheetName}
, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': Bearer ${access_token}
}
});
const result = await getSheet.json();
// Calculate the next available row by counting existing rows
const nextRow = result.values ? result.values.length + 1 : 1;
const rangeNotation = ${sheetName}!A${nextRow}
;
// Prepare the data to be appended
const data = {
range: rangeNotation,
majorDimension: "ROWS",
values: [dataArray] // Wrap the dataArray in an array to match the expected format
};
// Make the API request to append the data
const url = https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${sheetName}!A:A:append?valueInputOption=RAW
;
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
Authorization: Bearer ${access_token}
}
});
const updates = await response.json();
return updates;
}12 replies
BBuildShip
•Created by July on 4/11/2024 in #💬・general
July - Hey, the google sheet add row doesnt see...
I wasnt using a template literal in which case nothing happened
12 replies
BBuildShip
•Created by July on 4/11/2024 in #💬・general
July - Hey, the google sheet add row doesnt see...
Oh yeah it works, bad syntax on my part. Thanks!
12 replies
BBuildShip
•Created by July on 4/11/2024 in #💬・general
July - Hey, the google sheet add row doesnt see...
The node runs fine but nothing happens in the doc, maybe some mistake on my part.
12 replies
BBuildShip
•Created by July on 4/11/2024 in #💬・general
July - Hey, the google sheet add row doesnt see...
oo okay i will try again
12 replies