Transfer images between Google Sheets? - google-sheets-api

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?)

Related

What is the query parameter used by Google for setting custom headers in the exported pdf?

Using Google Sheets and working on a script to make exporting (downloading) a PDF copy of a single sheet much easier. The end goal is to emulate the Download as... PDF, but click of a button and it's done, without having to go to the menu. Also uses a custom file name (which includes the date and time).
The question...
When exporting a sheet using a script, is there a way to customize the content of the headers? I know when doing it manually, I can customize what appears in the headers and footers, but what about a script to change the top (or bottom) left/center/right areas when exporting a PDF via script? I know I can optionally enable a title (printtitle=true) or sheet name (sheetnames=true), but I can't find anything to permit me to customize what appears.
What I would like is to have a custom name/string for the top left and top center, then the date and time in the top right.

Update an existing PDF

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

Export Google Sheet to PDF Programmatically with Custom Parameters

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

How do I save an image as resource in Excel and reference it in Footer?

I am trying to embed a logo in the footer of a dynamically generated spreadsheet.
My first thought was to see what "macro recorder" would provide. Unfortunately, it references an image on the user's computer. The problem is that, in most cases, this file will not exist, and I don't want the user to have to download an image for the VBA script to be functional.
Is it possible to store an image in a VBA-enabled spreadsheet as a resource and then reference it from the footer?

How to edit Charts in Google Spreadsheet with Google SpreadSheet API in VB

I have a spreadsheet on my Google Account and I have some code which edits cells in this spreadsheet. Now I'm looking for a way to edit and(/or) make a new Chart in the worksheet I'm working on. I'm using the Google Spreadsheet API to edit the cells.
I did some hours of research on this topic but I just can't find how it would work. My understanding is that it is impossible with this API to work with charts. Is this correct?
I also found something about a Visualization api, but I can't figure out how to get this to work in vb, let alone how to make sure the chart I create would end up in my spreadsheet.
I want to use this chart on my own website, and I don't want to have to run the code before the graph updates. In other words, when I change the information in the cells manually via my spreadsheet I want these numbers to end up in my chart. I only want to change the chart via my code when I need to add a row or column to the chart.
Lastly, I've also read it is not possible at all to edit charts in a spreadsheet via a program. If so, I'd like to say to Google: WHY NOT!! AARGH. And maybe someone can suggest an other way to automatically update a chart which I can place on my website. (Again I want a live representation of the spreadsheet and the code I'm creating will only be run once a day if at all).
Thanks you so much for your time!
Google have Script inside the Spreadsheets that can do that for you.
https://developers.google.com/apps-script/reference/charts/