SlideShare a Scribd company logo
EPiServer Report Generation
In this blog I will be creating a Word Report on the Alloy Web Site using the Json, I generated
in my blog Usage Reports Schedule Job in EPiServer.
Word Generation
Before I can create a report I need to choose an approach. Custom API’s (DocX) or
generating Word compatible HTML are options. However, I’ve chosen to use the scripting
language PowerShell with COM (Component Object Model), to allows anyone to customize
the reports generation. I will have a dependency on MS Word. But give me full access to
word's functionality and I will be ensured full compatibility.
For development, I will be using the Windows PowerShell ISE.
Extract Json
I firstly I need to set a variable $root to the location where the script is running, in this folder,
this will be used thought out my script. In this folder, I’ve placed the UsageReport.zip which
will be used with the Extract-ZipFile command to copy the contents into the temporary folder.
$root = (Get-Item -Path "." -Verbose).FullName;
Extract-ZIPFile –File "$rootUsageReport.zip" -Destination
"$root$tmpFolder";
Now we can use the Get-Content command to read the JSON file and pass it to
ConvertFrom-Json, which will generate a valid object or collection.
$contentTypes = Get-Content -Raw -Path "$roottmpcontentproperties-
zreport.json" | ConvertFrom-Json;
Due to the dynamic nature of PowerShell, we don’t need to worry about creating POC
classes, as would be the case with a purely statically typed language.
Create New Document
We’re now ready to create our word document. First we instantiate the word COM object.
Here I also set word to be visible to allows us to check on the progress. However, if you were
developing this for a server, you naturally would set this to false.
$word = New-Object -ComObject word.application;
$word.visible = $true;
Now, we can create the document, below I’ve also included a template, so I can predetermine
the style and give it a basic structure.
$doc = $word.documents.add("$rootDefaultTemplate.dotx");
Next I’ll update a couple of document properties, which will are used on the cover page.
$doc.BuiltInDocumentProperties["Title"].Value = "EPiServer Report";
$doc.BuiltInDocumentProperties["Subject"].Value = "An Automatically
generated epierver Report on the content types";
Creating the structure
By using heading correctly, you create structure inside a word document. This structure can
be used to generate TOC (table of contents). In fact, the template that I used in the previous
section contained a TOC.
$selection.TypeParagraph();
$selection.style = "Heading 1";
$selection.TypeText("Introduction");
$selection.TypeParagraph();
$selection.style = "Normal";
$selection.TypeText("This document is divided into multiple sections");
$selection.TypeParagraph();
$selection.style = "Heading 2";
$selection.TypeText("Content Types");
The above code creates two heading and with normal text between. The rule for heading are
similar to HTML. You start with 1 and progress down, with more sub heading’s allows below
its parent.
Creating a table
Now we have a structure we need to create a table. However, we do need to know the total
number of rows and columns, plus an additional row for the heading.
$totalRows = $;content.Properties
$table = $doc.Tables.Add($selection.Range, $totalRows + 1, 7);
Now we can add individual cell for the heading row.
$table.Cell(1,1).Range.Text = "Name";
$table.Cell(1,2).Range.Text = "EPiServer Type";
…
It’s also possible to style the cell, for instance some of the cell will only be filed with a Boolean
(T/F) value. This means if the header cell’s text is vertical I’ll save space.
$table.Cell(1,7).Range.Font.Size = 8;
$table.Cell(1,7).Range.Orientation = 3;
$table.Cell(1,7).Range.Text = "Required";
Now we just need to loop from the collection of objects returned from the Json, remember to
start at 2, we use row 1 for the heading.
$p = 2;
foreach ($property in $content.Properties | Sort-Object TabName) {
$table.Cell($p,1).Range.Text = $property.EditCaption;
$table.Cell($p,2).Range.Text = $property.TypeName;
…
$table.Cell($p,7).Range.Text = ?: $property.Required "T" "F";
$p++;
}
Finally, I need to styling the table.
$table.Style = "Grid Table 4 - Accent 1";
Here I’ve chosen to use an inbuilt style, however it’s possible to create a custom table style
and save it as part of the template.
Saving the report
Now we’ve finished generating out report, we can save it, which is possible to do with one
line. However, this also require us to know enumerate value for the second parameter of the
saveas method. For Word Documents its 0 and PDF’s it’s 17.
However, to prevent the use of magic numbers I’ve import the Word Interop assembly and
retrieved the value directly.
$wdTypes = Add-Type -AssemblyName 'Microsoft.Office.Interop.Word' -
Passthru;
$wdDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat],
"wdFormatDocument");
$doc.saveas([ref] "$rootContent-Type-Report", [ref]$wdDoc);
Finally, we finish up by closing the generate document and quitting word.
$doc.Close();
$word.quit();
Conclusion
The biggest problem with this developing this script is knowing when to stop. For instance, I
could just as easily update the report and add Background tasks or Plugin. Alternatively, I
could change how the properties table works by the group the row by the Tab Column and
adding more columns.
My final script along with a couple of examples can be found by following the link below.
http://bit.ly/1nkWQGF
PowerShell is built on the NET Framework and give you access to COM and WMI (Windows
Management Instrumentation). This gives you the ability to not only generate Word and other
Office document types but also perform a wide variety of tasks. This means PowerShell is a
must for any windows developer or administrators.
Additional Resources
 http://bit.ly/20kTkuy - MS-Word with HTML & CSS
 http://bit.ly/23kJ8ES - DocX C# MS Word API
 http://bit.ly/1KwzKCx - XML-FO

More Related Content

What's hot

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
Ruby on Rails For .Net Programmers
Ruby on Rails For .Net ProgrammersRuby on Rails For .Net Programmers
Ruby on Rails For .Net Programmers
daveverwer
 
Database presentation
Database presentationDatabase presentation
Database presentationwebhostingguy
 
Php Training Workshop by Vtips
Php Training Workshop by VtipsPhp Training Workshop by Vtips
Php Training Workshop by Vtips
Vidya Topa Institute of Professional Studies
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.fRui Apps
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code LabColin Su
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
glslarmenta
 
Couchbase & FTS
Couchbase & FTSCouchbase & FTS
Couchbase & FTS
Rich Lee
 
Web 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHPWeb 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHP
Mohammad Imam Hossain
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Caldera Labs
 
Getting Creative with WordPress Queries, Again
Getting Creative with WordPress Queries, AgainGetting Creative with WordPress Queries, Again
Getting Creative with WordPress Queries, Again
DrewAPicture
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
Sencha
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Ivan Chepurnyi
 
Rails 3 Beautiful Code
Rails 3 Beautiful CodeRails 3 Beautiful Code
Rails 3 Beautiful Code
GreggPollack
 
Angular Data
Angular DataAngular Data
Angular Data
Stefan Unterhofer
 

What's hot (20)

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Ruby on Rails For .Net Programmers
Ruby on Rails For .Net ProgrammersRuby on Rails For .Net Programmers
Ruby on Rails For .Net Programmers
 
Apache Velocity 1.6
Apache Velocity 1.6Apache Velocity 1.6
Apache Velocity 1.6
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
lab56_db
lab56_dblab56_db
lab56_db
 
Php Training Workshop by Vtips
Php Training Workshop by VtipsPhp Training Workshop by Vtips
Php Training Workshop by Vtips
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
Couchbase & FTS
Couchbase & FTSCouchbase & FTS
Couchbase & FTS
 
Php summary
Php summaryPhp summary
Php summary
 
Web 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHPWeb 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHP
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 
Getting Creative with WordPress Queries, Again
Getting Creative with WordPress Queries, AgainGetting Creative with WordPress Queries, Again
Getting Creative with WordPress Queries, Again
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
Rails 3 Beautiful Code
Rails 3 Beautiful CodeRails 3 Beautiful Code
Rails 3 Beautiful Code
 
Angular Data
Angular DataAngular Data
Angular Data
 

Viewers also liked

Magical Mistery 10th Class Esciting
Magical Mistery 10th Class EscitingMagical Mistery 10th Class Esciting
Magical Mistery 10th Class Escitingarmax
 
THE VILLAGE COUNTY NEW
THE VILLAGE COUNTY NEWTHE VILLAGE COUNTY NEW
THE VILLAGE COUNTY NEWRaj Rajput
 
Matematica estas ahi
Matematica estas ahiMatematica estas ahi
Matematica estas ahi
GABY220597
 
Ela Awasthi-NEW RESUME
Ela Awasthi-NEW RESUMEEla Awasthi-NEW RESUME
Ela Awasthi-NEW RESUMEEla Awasthi
 
World Team School
World Team SchoolWorld Team School
World Team School
traderruss
 
Портфоліо
ПортфоліоПортфоліо
Портфоліо
Lilia Semerenko
 
Presentacion power point catedra
Presentacion power point catedraPresentacion power point catedra
Presentacion power point catedra
Dimelza Virguett
 
презентація Семеренко Л. А.
презентація  Семеренко Л. А.презентація  Семеренко Л. А.
презентація Семеренко Л. А.
Степненська Зш Степное
 
Becoming an Agile Leader, Regardless of Your Role
Becoming an Agile Leader, Regardless of Your RoleBecoming an Agile Leader, Regardless of Your Role
Becoming an Agile Leader, Regardless of Your Role
Johanna Rothman
 

Viewers also liked (13)

Resume
ResumeResume
Resume
 
Necessities of Life
Necessities of LifeNecessities of Life
Necessities of Life
 
Magical Mistery 10th Class Esciting
Magical Mistery 10th Class EscitingMagical Mistery 10th Class Esciting
Magical Mistery 10th Class Esciting
 
THE VILLAGE COUNTY NEW
THE VILLAGE COUNTY NEWTHE VILLAGE COUNTY NEW
THE VILLAGE COUNTY NEW
 
Matematica estas ahi
Matematica estas ahiMatematica estas ahi
Matematica estas ahi
 
Ela Awasthi-NEW RESUME
Ela Awasthi-NEW RESUMEEla Awasthi-NEW RESUME
Ela Awasthi-NEW RESUME
 
World Team School
World Team SchoolWorld Team School
World Team School
 
OSI Model
OSI ModelOSI Model
OSI Model
 
CD Media
CD MediaCD Media
CD Media
 
Портфоліо
ПортфоліоПортфоліо
Портфоліо
 
Presentacion power point catedra
Presentacion power point catedraPresentacion power point catedra
Presentacion power point catedra
 
презентація Семеренко Л. А.
презентація  Семеренко Л. А.презентація  Семеренко Л. А.
презентація Семеренко Л. А.
 
Becoming an Agile Leader, Regardless of Your Role
Becoming an Agile Leader, Regardless of Your RoleBecoming an Agile Leader, Regardless of Your Role
Becoming an Agile Leader, Regardless of Your Role
 

Similar to EPiServer report generation

What is PHPOffice?
What is PHPOffice?What is PHPOffice?
What is PHPOffice?Mark Baker
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3tutorialsruby
 
<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/
<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/
<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3tutorialsruby
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
Diacode
 
More Asp
More AspMore Asp
More Asp
guest4c97670
 
Angular Schematics
Angular SchematicsAngular Schematics
Angular Schematics
Christoffer Noring
 
Oracle Endeca Developer's Guide
Oracle Endeca Developer's GuideOracle Endeca Developer's Guide
Oracle Endeca Developer's Guide
Keyur Shah
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Adrien Guéret
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
LiquidHub
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2
RORLAB
 
Learning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client DevelopersLearning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client Developers
Kathy Brown
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
Rob Dunn
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
David Wheeler
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
markparolisi
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
Aravindharamanan S
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
Beau Lebens
 
WEB DEVELOPMENT
WEB DEVELOPMENTWEB DEVELOPMENT
WEB DEVELOPMENT
Gourav Kaushik
 

Similar to EPiServer report generation (20)

What is PHPOffice?
What is PHPOffice?What is PHPOffice?
What is PHPOffice?
 
Lecture14
Lecture14Lecture14
Lecture14
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/
<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/
<b>PHP</b>/MySQL <b>Tutorial</b> webmonkey/programming/
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
More Asp
More AspMore Asp
More Asp
 
Angular Schematics
Angular SchematicsAngular Schematics
Angular Schematics
 
Oracle Endeca Developer's Guide
Oracle Endeca Developer's GuideOracle Endeca Developer's Guide
Oracle Endeca Developer's Guide
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2
 
Learning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client DevelopersLearning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client Developers
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
WEB DEVELOPMENT
WEB DEVELOPMENTWEB DEVELOPMENT
WEB DEVELOPMENT
 

More from Paul Graham

Publising a nuget package
Publising a nuget packagePublising a nuget package
Publising a nuget package
Paul Graham
 
A guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled JobA guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled Job
Paul Graham
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServer
Paul Graham
 
Adding disqus to ghost blog
Adding disqus to ghost blogAdding disqus to ghost blog
Adding disqus to ghost blog
Paul Graham
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
Paul Graham
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
Paul Graham
 
Entity framework (EF) 7
Entity framework (EF) 7Entity framework (EF) 7
Entity framework (EF) 7
Paul Graham
 
Code syntax highlighting in ghost
Code syntax highlighting in ghostCode syntax highlighting in ghost
Code syntax highlighting in ghost
Paul Graham
 

More from Paul Graham (8)

Publising a nuget package
Publising a nuget packagePublising a nuget package
Publising a nuget package
 
A guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled JobA guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled Job
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServer
 
Adding disqus to ghost blog
Adding disqus to ghost blogAdding disqus to ghost blog
Adding disqus to ghost blog
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
 
Entity framework (EF) 7
Entity framework (EF) 7Entity framework (EF) 7
Entity framework (EF) 7
 
Code syntax highlighting in ghost
Code syntax highlighting in ghostCode syntax highlighting in ghost
Code syntax highlighting in ghost
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

EPiServer report generation

  • 1. EPiServer Report Generation In this blog I will be creating a Word Report on the Alloy Web Site using the Json, I generated in my blog Usage Reports Schedule Job in EPiServer.
  • 2. Word Generation Before I can create a report I need to choose an approach. Custom API’s (DocX) or generating Word compatible HTML are options. However, I’ve chosen to use the scripting language PowerShell with COM (Component Object Model), to allows anyone to customize the reports generation. I will have a dependency on MS Word. But give me full access to word's functionality and I will be ensured full compatibility. For development, I will be using the Windows PowerShell ISE.
  • 3. Extract Json I firstly I need to set a variable $root to the location where the script is running, in this folder, this will be used thought out my script. In this folder, I’ve placed the UsageReport.zip which will be used with the Extract-ZipFile command to copy the contents into the temporary folder. $root = (Get-Item -Path "." -Verbose).FullName; Extract-ZIPFile –File "$rootUsageReport.zip" -Destination "$root$tmpFolder"; Now we can use the Get-Content command to read the JSON file and pass it to ConvertFrom-Json, which will generate a valid object or collection. $contentTypes = Get-Content -Raw -Path "$roottmpcontentproperties- zreport.json" | ConvertFrom-Json; Due to the dynamic nature of PowerShell, we don’t need to worry about creating POC classes, as would be the case with a purely statically typed language.
  • 4. Create New Document We’re now ready to create our word document. First we instantiate the word COM object. Here I also set word to be visible to allows us to check on the progress. However, if you were developing this for a server, you naturally would set this to false. $word = New-Object -ComObject word.application; $word.visible = $true; Now, we can create the document, below I’ve also included a template, so I can predetermine the style and give it a basic structure. $doc = $word.documents.add("$rootDefaultTemplate.dotx"); Next I’ll update a couple of document properties, which will are used on the cover page. $doc.BuiltInDocumentProperties["Title"].Value = "EPiServer Report"; $doc.BuiltInDocumentProperties["Subject"].Value = "An Automatically generated epierver Report on the content types";
  • 5. Creating the structure By using heading correctly, you create structure inside a word document. This structure can be used to generate TOC (table of contents). In fact, the template that I used in the previous section contained a TOC. $selection.TypeParagraph(); $selection.style = "Heading 1"; $selection.TypeText("Introduction"); $selection.TypeParagraph(); $selection.style = "Normal"; $selection.TypeText("This document is divided into multiple sections"); $selection.TypeParagraph(); $selection.style = "Heading 2"; $selection.TypeText("Content Types"); The above code creates two heading and with normal text between. The rule for heading are similar to HTML. You start with 1 and progress down, with more sub heading’s allows below its parent.
  • 6. Creating a table Now we have a structure we need to create a table. However, we do need to know the total number of rows and columns, plus an additional row for the heading. $totalRows = $;content.Properties $table = $doc.Tables.Add($selection.Range, $totalRows + 1, 7); Now we can add individual cell for the heading row. $table.Cell(1,1).Range.Text = "Name"; $table.Cell(1,2).Range.Text = "EPiServer Type"; … It’s also possible to style the cell, for instance some of the cell will only be filed with a Boolean (T/F) value. This means if the header cell’s text is vertical I’ll save space. $table.Cell(1,7).Range.Font.Size = 8; $table.Cell(1,7).Range.Orientation = 3; $table.Cell(1,7).Range.Text = "Required";
  • 7. Now we just need to loop from the collection of objects returned from the Json, remember to start at 2, we use row 1 for the heading. $p = 2; foreach ($property in $content.Properties | Sort-Object TabName) { $table.Cell($p,1).Range.Text = $property.EditCaption; $table.Cell($p,2).Range.Text = $property.TypeName; … $table.Cell($p,7).Range.Text = ?: $property.Required "T" "F"; $p++; } Finally, I need to styling the table. $table.Style = "Grid Table 4 - Accent 1"; Here I’ve chosen to use an inbuilt style, however it’s possible to create a custom table style and save it as part of the template.
  • 8. Saving the report Now we’ve finished generating out report, we can save it, which is possible to do with one line. However, this also require us to know enumerate value for the second parameter of the saveas method. For Word Documents its 0 and PDF’s it’s 17. However, to prevent the use of magic numbers I’ve import the Word Interop assembly and retrieved the value directly. $wdTypes = Add-Type -AssemblyName 'Microsoft.Office.Interop.Word' - Passthru; $wdDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument"); $doc.saveas([ref] "$rootContent-Type-Report", [ref]$wdDoc); Finally, we finish up by closing the generate document and quitting word. $doc.Close(); $word.quit();
  • 9. Conclusion The biggest problem with this developing this script is knowing when to stop. For instance, I could just as easily update the report and add Background tasks or Plugin. Alternatively, I could change how the properties table works by the group the row by the Tab Column and adding more columns. My final script along with a couple of examples can be found by following the link below. http://bit.ly/1nkWQGF PowerShell is built on the NET Framework and give you access to COM and WMI (Windows Management Instrumentation). This gives you the ability to not only generate Word and other Office document types but also perform a wide variety of tasks. This means PowerShell is a must for any windows developer or administrators. Additional Resources  http://bit.ly/20kTkuy - MS-Word with HTML & CSS  http://bit.ly/23kJ8ES - DocX C# MS Word API  http://bit.ly/1KwzKCx - XML-FO