Wait For (j) JobDone(j As HttpJob)
If j.Success Then
StrGS=j.GetString
LblFromGS.Text=StrGS
End If
j.Release
I tried a lot to update the value of a cell in google sheet but not successful yet. I tested all examples in B4A forum but nothing worked for me. Can everybode help me. I just want a simple code to update the value of one cell for example B3.
Gsheet Author: Fernando Arevalo Version: 1.0 Functions: Process_Globals As String B4A, B4I Initialize (ClientId As String) B4J Initialize(ClientId As String,ClientSecret As String) B4X SpreadsheetsId As String The ID of your document. This is the big long aplha-numeric code in the...
Gsheet Author: Fernando Arevalo Version: 1.0 Functions: Process_Globals As String B4A, B4I Initialize (ClientId As String) B4J Initialize(ClientId As String,ClientSecret As String) B4X SpreadsheetsId As String The ID of your document. This is the big long aplha-numeric code in the...
Understood: I'm just trying to distil what the true problem is that makes it not possible for him to buy it, in case there is an easy solution to that secondary issue.
That library looks pretty good, btw, so thanks for the prompt pointing it out.
Understood: I'm just trying to distil what the true problem is that makes it not possible for him to buy it, in case there is an easy solution to that secondary issue.
That library looks pretty good, btw, so thanks for the prompt pointing it out.
You can use Google App Script (GAS) and publish the sheet as web app so you can access it by okhttp easily by WEB APP URL. Here is the GAS if you want:
Google App Script:
function doGet(e) {
const sheet = SpreadsheetApp.openById('google sheet ID').getActiveSheet();
const action = e.parameter.action;
if (action === 'read') {
const data = sheet.getDataRange().getValues();
return ContentService.createTextOutput(JSON.stringify(data)).setMimeType(ContentService.MimeType.JSON);
}
if (action === 'create') {
const values = JSON.parse(e.parameter.values);
sheet.appendRow(values);
return ContentService.createTextOutput('Row added successfully');
}
if (action === 'update') {
const row = parseInt(e.parameter.row, 10);
const values = JSON.parse(e.parameter.values);
for (let i = 0; i < values.length; i++) {
sheet.getRange(row, i + 1).setValue(values[i]);
}
return ContentService.createTextOutput('Row updated successfully');
}
if (action === 'delete') {
const row = parseInt(e.parameter.row, 10);
sheet.deleteRow(row);
return ContentService.createTextOutput('Row deleted successfully');
}
return ContentService.createTextOutput('Invalid action');
}
You can use Google App Script (GAS) and publish the sheet as web app so you can access it by okhttp easily by WEB APP URL. Here is the GAS if you want:
Google App Script:
function doGet(e) {
const sheet = SpreadsheetApp.openById('google sheet ID').getActiveSheet();
const action = e.parameter.action;
if (action === 'read') {
const data = sheet.getDataRange().getValues();
return ContentService.createTextOutput(JSON.stringify(data)).setMimeType(ContentService.MimeType.JSON);
}
if (action === 'create') {
const values = JSON.parse(e.parameter.values);
sheet.appendRow(values);
return ContentService.createTextOutput('Row added successfully');
}
if (action === 'update') {
const row = parseInt(e.parameter.row, 10);
const values = JSON.parse(e.parameter.values);
for (let i = 0; i < values.length; i++) {
sheet.getRange(row, i + 1).setValue(values[i]);
}
return ContentService.createTextOutput('Row updated successfully');
}
if (action === 'delete') {
const row = parseInt(e.parameter.row, 10);
sheet.deleteRow(row);
return ContentService.createTextOutput('Row deleted successfully');
}
return ContentService.createTextOutput('Invalid action');
}
Hi
Thanks for your response.
I create a new Spreadsheet and add your code to "Apps script" section in "Extensions" menu of the spereadsheet. I run it and allowed the required access to my google account.
This method is correct?
If yes, can you please show me how to update a cell in the spreadsheet using Okhttp?
Hi
Thanks for your response.
I create a new Spreadsheet and add your code to "Apps script" section in "Extensions" menu of the spereadsheet. I run it and allowed the required access to my google account.
This method is correct?
If yes, can you please show me how to update a cell in the spreadsheet using Okhttp?
Click Deploy > New Deployment.
Select Web app.
Under "Who has access," select Anyone
Copy the Web App URL (it will look like this: https://script.google.com/macros/s/.../exec).
Please find attached b4j example for upating row 2. I have given all CRUD operations functions too for you to check.