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
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?)
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.
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
I cannot figure out how to change the document formatting options through the Google Drive API. Is this not supported? As of now I am uploading a file but Google is making the line height 1.15, but I want it to be Single (or 1).
Google Drive doesn't provide fine-grained controls to alter Google Docs, Sheets, etc. You can import files in other formats and convert them to Google formats, but you can't manipulate individual properties of the resulting files, including line height.
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?