• Danish Yasin

Creating Powerpoint Slides From Templates

Updated: Oct 16



Powerpoint presentations are used whether you are presenting a new product to the world or when you are explaining the budget to the stakeholders. More often than not, these presentations require the inclusion of data that is stored in a database of some sort. Manually extracting the data and converting it into meaningful presentations can be burdensome and slow.


This is especially true if you are not employing tools that can improve this process and automate the presentation creation process. This could be a simple Golang script that reads from your excel sheet and provides you with meaningful output.


However, you cannot directly create powerpoint presentations using Golang. This is where UniOffice helps you and provides you with an interface through which you can transform raw data into beautiful presentations with minimal manual labor.


Your data could be in an excel sheet, in a database or some other data source. Using UniOffice, you can get data from anywhere and use it in your presentations directly. In this article, we will show you how you can use a sample data stored in JSON format for creating presentations by using methods provided by UniOffice.


We’ll be using the empty template shown in the image below to create our required presentations. This tutorial is loosely based on the example found in our GitHub repository here.



Figure 1: An empty presentation used as a template



Creating Presentations Through UniDoc


The first step is to import all of the required packages:



The next thing you should do is insert your license key, you can get the license key by filling out the free trial form on the UniDoc website.


Once you have the license key, place it in the licenseKey variable and you are reading to start.



In this tutorial, we are getting the data from a JSON, so for that purpose, we first define the struct that will be used to parse the JSON. Here are the two required structs.



We are defining a very basic sales data for some localities. Here is the example data that we will be using in the proceeding steps. The purpose of this tutorial is to guide you regarding the capabilities of the UniDoc library and show you what is possible. By following this guide, we hope that you will be able to extend the application to your own use cases.



Next up, we have a basic template presentation, which you can download from our GitHub repository. The template is just used to select the theme of the presentation and we will now programmatically insert data into it now.



After opening the template, let’s read the aforementioned JSON into the struct we defined earlier. We can do this by using the encoding/json package that uses the Unmarshal() method to complete this step.



We have all the sale data in the saleData variable. Now, let’s iterate through all the records and create a presentation for each one of them.


Let’s create the loop and for each record, clear the template presentation file before proceeding:



The next step is to insert the relevant data into the relevant paragraphs. Since we are looping through the structs, we can access their properties using the (.) dot operator and consequently, place them inside the presentation.



And lastly, let’s check for an error and move on to saving the file named after the area of the sale data.



With this, we now should have multiple presentations ready according to our data. An example of a document created from the above code is shown in the figure below.


Figure 2: A presentation created from the template


Sky's the Limit

Here's the playground example for the code described above. No license key is required to run the code on our playground. You can test out the libraries of UniDoc on playground and tinker around with existing examples to check out what you can do with them.




Sky's the Limit


In this tutorial, we highlighted a powerful feature of UniDoc with a very simple data source. By understanding the core concepts behind UniDoc, you should be able to extend these principles onto complex projects and create enterprise level applications.


To check out more of our examples on how you can use UniOffice to fulfill your office requirements, check out our GitHub repository for UniOffice examples. We also host a rich set of examples for UniPDF, which you can check out here. If you want an additional feature to be added, open an issue on GitHub. We are actively improving ourselves to meet the requirements of our users.

© All rights reserved to unidoc.io

linkedin-icon.png