Skip to content

Generating PowerPoint reports with LokqlDX

NeilMacMullen edited this page Jan 1, 2025 · 1 revision

LokqlDx can be used to author or revise powerpoint reports in the open-xml format. Query results can injected into a report template as images, tables or plain text while retaining the template styling and attributes.

The basic recipe is...

  • Create a pptx template containing some named "placeholder" images, tables and text elements
  • Use the .startreport command to load the template
  • Use a succession of .addtoreport commands to insert content into the template
  • Save the report out to a new file using the .finishreport command.

Creating the template

You'll need to create a pptx file with at least one slide. The .addtoreport command works by searching for a named element of the appropriate type. If no element can be found, one is added at the end of the presentation. This behaviour is intended to make it easier to quickly scaffold reports from existing queries.

Naming elements

Elements are named within PowerPoint via the "Selection Pane" menu. The easiest way to access this is to use the Search tool...

image

Element behaviour

Charts can be inserted as images. Chart images will be generated using the width and height dimensions of the image found in the template.

Data can also be inserted into tables Tables will be automatically resized to the required number of rows and columns so that they fit the result data.

Data can be inserted as text on any shape. If the source result has more than one cell only the contents of the cell at 0,0 is used.

Example script

# generate some stored results from data

mydata | summarize count() by Type | render piechart
.push breakdownByType

mydata | where Type=='unknown'
.push unknownTypes

mydata | count 
.push itemcount

# load the template, insert the results, and then save out to a new file
.startreport pptx c:\reports\template.pptx
.addtoreport title "This is a report generated by lokqldx"
.addtoreport image breakdownbyType
.addtoreport table unknownTypes
.addtoreport text itemcount
.finishreport c:\reports\week1.pptx