Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Coding noob here, trying to learn...

I'm trying to take a range of cells in one google spreadsheet (not contiguous to any page/sheet border), convert the range to pdf, then email the pdf as an email attachment to a specified address. I can use a prewritten addin, but then I won't learn. A person only learns by asking questions.

I googled for answers, and got to this website (https://ctrlq.org/code/19869-email-google-spreadsheets-pdf). Trouble is, this script sends all of the sheets in a zip file. I don't want to do this. I just want to send, as a pdf, a range of selected cells located in only the first sheet and as a pdf, NOT a zip file.

My almost nonexistent javascript education tells me that my script uses the following code snippet to obtain the relevant data: (Obviously, I might be wrong...)

// Get the currently active spreadsheet URL (link)
// Or use SpreadsheetApp.openByUrl("<<SPREADSHEET URL>>");
var ss = SpreadsheetApp.getActiveSpreadsheet();

I don't know if I've got the correct snippet, which is why I included the URL of its source. Anyhow, I simply want to send a range starting at row 2 column 3 and ending at row 31 column 12. 7 days later, I want to use another script to send a different range.

How can I modify this script to achieve my goal?

Thanks to everyone who can help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
160 views
Welcome To Ask or Share your Answers For Others

1 Answer

First of all you need to understand what you are asking for and what it's really called.

As noted in the comment by Robin Gertenbach you should look at the Google Documentation first. Only after you have exhausted the information there should you look elsewhere for code snippets etc. The reason I am saying this is that a range is most likely not what you think it is. The range object itself is not data you need but is a class that you can use to obtain the information instead.

For example if you want values you would do something like SpreadsheetApp.getActiveRange().getValues() which would return an 2 array of string values. However, there is no such method to output a string of characters as a pdf. Logically a PDF is a document, so to get a PDF you need to export a document. The lowest document type is the actual spreadsheet and in the documentation you can see that here

Anything else you can think off will come from Javascript and not Google Apps Script, so that is where you could look. The only alternative here is to create a new spreadsheet and save it as a pdf, then delete the spreadsheet.

The snippet you have is simply creating a variable with the entire spreadsheet as the object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...