How to print a page from a Google Sheet using a macro?

2,742 views
Skip to first unread message

claude_...@hotmail.com

unread,
Mar 1, 2022, 5:39:47 AM3/1/22
to Google Apps Script Community
I want to use a macro to print a page from a Google sheet, to either paper of PDF.

I tried the recorder but it doesn't record the printing steps.

I tried different examples that I found either had syntax errors or undefined errors.

A complete simple example would be useful.

Thank you

Edward Ulle

unread,
Mar 1, 2022, 8:59:46 AM3/1/22
to Google Apps Script Community
Not from macro but from script.  There are numerous articles on Google.  Take this one for example https://support.google.com/docs/thread/129491009/google-sheets-to-pdf-to-its-own-folder?hl=en

claude_...@hotmail.com

unread,
Mar 3, 2022, 11:50:47 AM3/3/22
to Google Apps Script Community
Many thanks,

I got it to all to work but, while the file created has the PDF extension, the format is HTML. See below the top portion of the file created:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta content="width=300, initial-scale=1" name="viewport">
...

the script has the line 'exportFormat=pdf&format=pdf', so what am I doing wrong?

Thanks again,

Claude

claude_...@hotmail.com

unread,
Mar 6, 2022, 1:05:21 PM3/6/22
to Google Apps Script Community
Anyone got the answer to my question: using the script from the link above, why is the format of the output file html instead of pdf?

Jonathan Butler

unread,
Mar 6, 2022, 3:37:27 PM3/6/22
to google-apps-sc...@googlegroups.com
Are you adding ".pdf" to the name of your file?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ac6afa2f-13ef-48e4-8ef3-d0ff2b3b8dabn%40googlegroups.com.

Clark Lind

unread,
Mar 8, 2022, 12:44:06 PM3/8/22
to Google Apps Script Community
Without seeing your code, it is hard to tell exactly where any error might be or why it is doing that. 
Reply all
Reply to author
Forward
0 new messages