0

I want to export my query results to Google Sheets. Is there some way to do it directly or using AppScript in Google Sheets.

Nahuel Varela
  • 1,022
  • 7
  • 17
Logical
  • 310
  • 1
  • 3
  • 13
  • The gcloud tool can help with this. Please see https://stackoverflow.com/questions/53451273/how-to-export-google-spanner-query-results-to-csv-or-google-sheets – Rose Liu Dec 20 '18 at 04:04
  • @RoseLiu Thanks, Will check it out. Can we somehow do it using AppScripts in Google sheets – Logical Dec 20 '18 at 05:06
  • This is written in some other answer, below is the link. https://stackoverflow.com/questions/53451273/how-to-export-google-spanner-query-results-to-csv-or-google-sheets – Arkanil Dutta Dec 20 '18 at 09:00
  • I'm 99% sure that there is not a native Spanner --> Apps Script connector – Jesse Scherer Dec 20 '18 at 15:52

1 Answers1

0

Right now it’s not possible to export from Google Cloud Spanner directly to Google Sheets through Google Apps Script.

One way to do it is as @RoseLiu commented, using @RedPandaCurios solution.

Another possible workaround could be to use Dataflow. You can export the Google Cloud Spanner database as a .csv file to Google Cloud Storage with Google Cloud Dataflow, then you import the .csv file to Google Sheets.

Dataflow has already available a template to export from Cloud Spanner to Cloud Storage. Once the job is finished, you can download from Storage the .csv file through the Console or using the API.

Nahuel Varela
  • 1,022
  • 7
  • 17
  • @JesseScherer I guess a good option would be launching the Dataflow job from a Google Cloud Function (as I explained [here](https://stackoverflow.com/a/48601579/1308883)), and from AppsScript just send the HTTP request that triggers the function itself using [UrlFetchApp](https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app). The issue with this solution is that we are adding more and more products to the solution: GCF, Dataflow with templates, GCS, Sheets API... – Jofre Dec 20 '18 at 19:42