问题
I am able to create a pdf from a single Google spreadsheet sheet using this code.
Is it possible to tweak this code to allow multiple sheets from different spreadsheets to be merged into a single pdf? Or would I need to take an entirely different approach?
回答1:
I guess you can't but you can easily merge spreadsheets into a temporary spreadsheet and export this one as pdf.
to merge sheets from different origins you have a choice of methods to choose from, below is a small example that gets 1 sheet from the active SS and one from another SS and merge it in a "temp" SS.
The destination spreadsheet will have 3 sheets :
- sheet1
- copy of sheet1
- copy of sheet1 1
You'll just have to clean it up and rename to your needs.
code :
function mergeSS(){
var dest = SpreadsheetApp.create('temp');
var s1 = SpreadsheetApp.getActive().getSheets()[0];// one opening method
var s2 = SpreadsheetApp.openById('1NmeLtT4_9jRzau__________o23KG8hYdJj6w').getSheets()[0];// another opening method
s1.copyTo(dest);
s2.copyTo(dest);
}
来源:https://stackoverflow.com/questions/25515853/is-it-possible-to-create-a-single-pdf-from-multiple-google-spreadsheets