I have a 3 column Spreadsheet [Date, Time, Subject] that I want to populate via the Sheets API using Java.
I understand how to read rows:
for (List row : values)
System.out.println(row.get(0) + row.get(1) + row.get(2));
But I am having trouble using their documentation to understand how to insert specific strings into specific rows and columns. I know there exists a method row.set(int index, Object element)
but when I try to insert a new row like this:
for (List row : values)
{
row.set(0, message.full_date);
row.set(1, message.time);
row.set(2, message.subject);
}
nothing is updating in my sheets. My full code:
private static void Update_Sheets(Sheets sheets_service, GmailMessage message) throws IOException
{
String spreadsheetId = id;
String range = "Sheet1!A1:C2";
ValueRange response = sheets_service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List<List<Object>> values = response.getValues();
for (List row : values)
{
row.set(0, message.full_date); //a string
row.set(1, message.time); //a string
row.set(2, message.subject); //a string
}
}