Skip to content

A Google ApssScript that will fill out a template file on Google Drive from a JSON input string. The script can be made accessbile as a web app to serve as template engine.

Notifications You must be signed in to change notification settings

komasoftware/gas-template-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

gas-template-engine

A Google ApssScript that will fill out a template file on Google Drive from a JSON input string. It will iterate over any array it finds in the JSON structure and create table rows per array value.

For example, give JSON structure :

 {"invoice":
	{"invoiceNumber":"00001",
	 "invoiceStatus":"OPEN",
	 "invoiceDate":"22-jun-2013",
	 "totalPriceExVat":"6.778,11 €",
  	 "totalPriceIncVat":"64.264,41 €",
	 "totalVat":"57.486,30 €",
	 "dueDate":"22-jul-2013",
	 "extraLines":"",
	 "paymentStatus":"UNPAID"
	},
   "invoiceItems":
		[
                   {
			"quantity":"6,63",
			"vatPercentage":"803%",
			"unitPrice":"831,74 €",
			"itemName":"item 1",
			"itemDescription":"nails",
			"priceExVat":"5.514,44 €",
			"vat":"44.280,95 €",
			"priceIncVat":"49.795,39 €"
		   },
		   {
			"quantity":"7,68",
			"vatPercentage":"1.045%",
			"unitPrice":"164,54 €",
			"itemName":"4a9133cf-c8a5-44d6-a849-a72a17ffc49d",
			"itemDescription":"d4431a69-35e5-4f86-8ec0-f9ebb2da33bf",
			"priceExVat":"1.263,67 €",
			"vat":"13.205,35 €",
			"priceIncVat":"14.469,02 €"
		   }      
		],
   "client":
		{
			"namePrefix":"",
			"name":"jan",
			"contactName":"jan smith",
			"companyName":"saas company",
			"email":"[email protected]",
		},
    "profile":{
		"companyName":"apps script producer limited","email":"[email protected]","phoneNumber":""
	}
};

Now create a Google Docs file and put place holders anywhere you like :

$client.namePrefix $invoice.invoiceNumber

Create a table and put $invoiceItems.quantity in one of the rows and the row will be repeated for the each array element.

I will provide an example any time soon.

About

A Google ApssScript that will fill out a template file on Google Drive from a JSON input string. The script can be made accessbile as a web app to serve as template engine.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published