Created
August 21, 2018 15:18
-
-
Save raghuvarmabh/76ee43f848c77f67d340a25094e6ede5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
var ui = SpreadsheetApp.getUi(); | |
// Or DocumentApp or FormApp. | |
ui.createMenu('XYZ Menu') | |
.addItem('Generate PO', 'createDcument') | |
.addToUi(); | |
} | |
function createDcument() { | |
var activeSheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var activeRange = activeSheet.getActiveRange(); | |
var row_data = activeRange.getDisplayValues(); | |
var scriptProperties = PropertiesService.getScriptProperties(); | |
var template_id = scriptProperties.getProperty('template_id'); // document template | |
/***Modify indexs if you the spread sheet columns shuffle **/ | |
var attributes = { | |
bill_no: "0", | |
vendor: "1" , | |
date: "2" , | |
description: "3" , | |
length: "4" , | |
width: "5", | |
height: "6", | |
weight: "7" | |
} | |
/****************/ | |
var documentId = DriveApp.getFileById(template_id).makeCopy().getId(); | |
DriveApp.getFileById(documentId).setName('Purchase Order PO# '+ row_data[0][3]); | |
var body = DocumentApp.openById(documentId).getBody(); | |
for (var prop in attributes) { | |
var index = attributes[prop]; | |
var propValue = row_data[0][index]; | |
propValue = propValue ? propValue : ""; | |
body.replaceText('##'+prop+'##', propValue); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment