1

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?

Community
  • 1
  • 1
Jared_C
  • 649
  • 1
  • 7
  • 16

1 Answers1

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);
}
Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • OK, thanks. I thought of this approach as well. My issue is I have over 100 different sheets to aggregate. I'm worried that I'll hit some sort of rate max or the temp spreadsheet won't like having so many sheets added. – Jared_C Aug 27 '14 at 19:30
  • Not sure it would fail... eventually add a small pause between SS creation using utilities.sleep(). I recently used a script that creates 20+ SS without issue (I know it's less than 100 but it was already not that bad ;-)- btw, thx for accepting. – Serge insas Aug 27 '14 at 20:40