Is it possible to download a chart from a google sheet using the API? I don't see any reference in the docs that describe how to save a chart to an image file.
Related
Is there a way, using the Google Sheets API, to transfer images from one Google Sheet to another that have been added using Insert > Image?
I had a look at the possibilities of Importrange but there doesn't seem to be a way to transfer images using that.
Answer:
Unfortunately, there is currently no way to retrieve images added through Insert > Image via Sheets API, so all you have are several roundabout ways, which will only be appropriate in certain circumstances.
Feature Requests:
There are several feature requests in Issue Tracker regarding image handling in Sheets API, I'd suggest you to star these in order to keep track of them and to help prioritize its implementation:
Retrieve "Image in Cell" cell data on spreadsheets.get endpoint
Insert images to Sheets using the API
Update OverGridImage to support BlobSource interface.
Workarounds:
Option 1. Set image through its URL:
If a URL of the image is available and you want to write the image to a specific cell (not over cells), you could just add the formula =IMAGE(your-image-url) to the desired cell via spreadsheets.values.update.
Or, if you're open to using Apps Script, you could use insertImage(url, column, row).
Option 2. Copy corresponding range:
If the image was added via Insert > Images > Image in cell and the destination sheet is on the same spreadsheet as the source sheet, you could make a CopyPasteRequest or a CutPasteRequest to copy or move the range containing the image to the destination sheet (see spreadsheets.batchUpdate).
Option 3. Copy the entire sheet:
If the image was added via Insert > Images > Image over cells, or if the destination sheet is not on the same spreadsheet as the source sheet, your only option would be to copy the entire sheet via spreadsheets.sheets.copyTo.
You can download a zip file with the sheet in html format using Google API. It will contain all images, no matter how were they added.
Get Your API Key, from Google developers Console
Get a File ID of a google spreadsheet with permissions set to "Anyone with the link".
Now you're ready to call the api (with curl or browser window):
https://www.googleapis.com/drive/v3/files/{FILE_ID}/export?mimeType=application%2Fzip&key={YOUR API KEY}
Remember to fill the above with Your FILE_ID and your API_KEY from google.
This works only for files with "anyone with link" permissions, otherwise you'll have to authenticate first. (see my answer here: How to send google-sheet data in an email keeping the formatting( colors) intact from python?)
I have an existing PDF template, and I want to add some text over the top of it in a specific location on a specific page. For example, an invoice template or a scanned document.
How would I go about this? I'm using Sheets if that narrows my options.
There is a lot of documentation on how to create PDFs from documents, but nothing that will take a particular PDF and put text over it.
A bit of blue sky thinking from my side. What if you were to do the following?
Manually:
Export the PDF as an image
Resize a Google slide to be the same shape as the image
Add the image to the google slide as a background image
In Code:
Make a copy of the google slide as needed
Add your Google sheets data to the slide positioned as needed on the slide
Export the Google slide as a pdf
I mention google slides, because Google docs to not have allow background images.
Another possibility with using Google docs is to build a document that looks like your invoice, then add to it tags. In your code search for the tags and replace them with data from your sheet. Even you could use a mail merge addon to do this if you didn't fancy writing any code.
In your Google Drive right-click on your PDF;
Open With > Connect More Apps > Search docusign > Left-click blue connect button and this should take you to Docusign.
Your PDF will then open with Docusign where you can manually add a signature or text to specific places.
Alternatively... You can use App Script.
Example,
Constructing a document using HTML and replacing the specific value with a variable which is collect from a Sheet or particular location. Writing the function to do this will allow you to interpret the HTML and replace the variable with the text or possibly an image. Then it would create this as a PDF.
There are many alternative ways to do this.
Here is one example on github;
Convert Google Doc to PDF using App Script
How do you export an entire Google Sheet to PDF in Landscape with fit to width, grid lines, page numbers, and spreadsheet name but not sheet name?
How about exporting the same as above but only 1 specific sheet in the spreadsheet or specific range within a sheet?
I can do all this through the GUI when exporting from a Google Sheet but no documented way via API.
I have found various sources showing how to do this via URL but have been unable to find any documentation by Google. The parameters used are not consist between sources and have been unable to figure out all the parameters available through the GUI.
How were the parameters determined? Is this documented by Google? Is this possible via API?
URL exporting sources:
https://issuetracker.google.com/issues/36761058#c25
Google Apps Script - Add landscape parameter to PDF email attachment
I want to export the content in a Google Spreadsheet as a .xlsx file. What should I do?
Is it possible to do with command-line? (like nodejs)
Thanks,
Download google spreadsheet
excel/pdf/HTML/csv etc
Use "Google drive API" - code:
Download a Google Docs Spreadsheet as HTML
You can download as anything that is offered by the Spreadsheet menu.
I suspect OAuth2 is required.
I'm looking for a way to convert text/xml/json (whatever) to a Google doc. The Googles docs api only allows you to create new presentations or upload presentations, not to edit the content of those presentations. I imagine a library or api which converts text to a powerpoint could be a major part of the process.