//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* Template Generator By: Andre Fecteau - klutch2013@gmail.com Original Code From: kiszal@gmail.com (Found in the template gallery by searching "Templates" It is the first One. Major Help from: Serge Insas On Stack Overflow (He did most of the work.) Link 1: http://stackoverflow.com/questions/18147798/e-undefined-google-script-error Link 2: http://stackoverflow.com/questions/18132837/have-a-listbox-populate-with-every-folder-in-mydrive How To Use: First: each column is designated in your Template by {Column Letter} for example for column A it would be {A} Second: You can change this, but your Template must be in a folder called "Templates." This folder can be anywhere in your drive. Third: Click "Generate Documents Here!" Then click "Export Row to Document" Fourth: Type in the row you want to export. Chose your Folder Path. Click Submit. NOTE ON FOURTH STEP: If you want your number to skip the header row add a +1 to line 32. This would mean if you typed "2" in the row box it actually exports row 3. I took this out because it can get confusing at times. NOTE: Line 71 you can edit the word "Templates" to whatever folder you saved your Template into. NOTE: Line 36 you can edit to change what comes up in the name of the file that is created. To do this just edit the column letter in the following piece: "+Sheet.getRange('E'+row).getValue()+" You can then delete any other columns you do not want by deleteing the section of code that looks like the following: '+Sheet.getRange('D'+row).getValue()+' Feel free to edit this code as you wish and for your needs. That is what I did with the original code. So there is no reason I should restrict what others do with this code. */ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function generateDocument(e) { var template = DocsList.getFileById(e.parameter.Templates); Logger.log(template.getName()); var Sheet = SpreadsheetApp.getActiveSpreadsheet(); var row = Number(e.parameter.row)//+1 ; // Remove the // in this line next to the +1 to skip headers Logger.log(row); var currentFID = e.parameter.curFID; Logger.log(currentFID); var myDocID = template.makeCopy(Sheet.getRange('B'+row).getValue()+' - '+Sheet.getRange('E'+row).getValue()+' - '+Sheet.getRange('D'+row).getValue()+' - '+Sheet.getRange('X'+row).getValue()).getId(); var myDoc = DocumentApp.openById(myDocID); var copyBody = myDoc.getActiveSection(); var Sheet = SpreadsheetApp.getActiveSpreadsheet(); row--; // decrement row number to be in concordance with real row numbers in sheet var myRow = SpreadsheetApp.getActiveSpreadsheet().getRange(row+":"+row); for (var i=1;i0){listF.clear(); listF.addItem('Select Sub Folder','x')}; for (var i = 0; i < folders.length; i++) { listF.addItem(folders[i].getName(),folders[i].getId()) } curFN.setText(currentFN+DocsList.getFolderById(currentFID).getName()+'/'); if(currentFID==DocsList.getRootFolder().getId()){curFN.setText('MyDrive/')}; curFID.setText(currentFID); return app; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries = [{name: "Export Row to Document", functionName: "getTemplates"}]; ss.addMenu("Generate Documents Here!", menuEntries); }