I usually use google cloud connect. wondering if I have spreadsheet always sync with my updated xlsx automatically. It's look like import button in spreadsheet or upload button in google drive, I think. How do apps script do this case?
we all expect to have a "convertToGDocsFormat" member in File's DocsList API. (Actually, we expect the makeCopy member to have an option to convert it in the copy process.)
But DocsList API is experimental and perhaps incomplete, it doesn't have such method yet.
For now you can't convert a file to Google format from a script.
There is another (long) way to read data from a xlsx. Supposed you have the xlsx file sync'ed. You can access it using the experimental DocsList API, and get a blob.
XLSX file is a ZIP file you can unzip with Utilities.unzip not documented method that gives you an un zipped blob.
Then you have to navigate the tree folder (in the blob) to get the XML files you want to read (from the blob). This tree folder and its XML files describe the entire XLSX spreadsheet.
Finally you may parse such XML file and navigate trough it and get cells' values.
This is not quick to code, nor to execute.
Related
I often make spreadsheets in Google Sheets by importing a collection of csv files. But whenever I import a csv file into a Google Sheets document, the csv file is uploaded to my Google Drive as well.
As a result, I have a huge number of csv files in my Google Drive that I don't want.
Can I stop this from happening? I want to import the csv into the Google Sheets document but I don't also need the csv file in my Google Drive.
A follow-up question is: if I can't prevent the csv from being uploaded to my drive, can I delete the csv from my drive without affecting the Google Sheets document?
This question is related to this one How to stop Google Sheets automatically saving downloaded CSV files to Google Drive, but they asked the question incorrectly, and never followed up with a corrected question.
The CSV files being uploaded to the Google Drive is necessary. It is due to the fact that Google Sheets will only look for the source files to be imported either from your personal Google Drive or from other people's Google Drive that are shared with you.
Suggestion
As for your issue on multiple csv files, you can create a script to automatically delete csv files from your Google Drive. However, the only available feature in Google Apps Script is to move the said files to a folder using the File.moveTo(destination) function since the removeFile(child) function was already deprecated. Afterwards, you may use the setTrashed(trashed) function to send the files to the trash folder.
References:
You may view the following links for further details on how to apply the suggestion.
removeFile(child)
moveTo(destination)
setTrashed(trashed)
Google Apps Script Deleting Google Drive Files in Folder Example
I tried to use Get(). I was able to read/update the file metadata but don't know how to get the file contents. From my googling I know I have to identify alt=media but I don't know how. Could anybody give a full example.
To retrieve the contents of a Gogle document like Google Sheets, Google Docs etc. you can use the Sheets API, Docs API etc. respectively
To retrieve the contents of a non-Google file on your Google Drive, like e.g. a text file - you cannot do it directly
Instead, you need to donwload the file to your local Drive
For this, when using the method Files: get, specify alt=media as you already know
However, this will not directly give you the file contents, but rather request a download of the contents from the server
In the next step you need to write this downloaded content to a file on your local machine
The Guide for downloading files stored on Google Drive provide samples of how to do so in Java, Python and Node.js
Is it possible to have a BigQuery query on a Google Drive folder if all CSV files in the folder have the same schema? Is it possible for the query to be updated automatically whenever a file is added or deleted? Just wondering whether this would require some Apps script or can just be done within BigQuery somehow.
Option 1: PubSub detection of Google Drive changes
You can likely do this via PubSub.
Then have the PubSub subscription be a PUSH notification to an Apps Script web service HTTP endpoint.
Your doGet() method in Apps Script can then do your normal import actions on that CSV based on the filename passed as a parameter in the PubSub HTTP push notification.
Option 2: Use BQ external tables
Link BQ to an external Google Drive source as an external table. This does not require "importing" data to BQ at all, it reads directly from CSV on Google Drive, etc.
how can I open a excel file directly with google sheets api
Not to my knowledge, however, using the Drive API you can upload and convert an Excel file to Sheets format automatically. This could then be used by the Sheets API. This may or may not work as a substitute in your use case.
Well you can read a .xlsx file as a binary blob from Google Apps Script API. So if you want to read the xlsx formatted file and do all the work of interpreting it yourself, then sure you can. But that's essentially writing the entire MS Excel interpreter in Google Script.
I'm looking for a way that I can programmatically get diffs of a file that is on Google Drive and information of who modified the file.
It seems that Google Drive API does not provide diffs, but they provide revisions of a file via Revisions API.
Revisions.list() method returns an URL of each revision of a file. So, it is possible to check the difference between two revisions if I download them and compare with each other.
But I cannot know who modified the file in this way. Response of Revisions.list() method returns only one editor of the file if other people are editing at the same time.
Does anyone have any idea how to get such data?
I found that I could see how & who modified a file on Google Drive.
( File -> See reision history )
Thanks