SlideShare a Scribd company logo
1 of 9
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 Programmersdaveverwer
 
Database presentation
Database presentationDatabase presentation
Database presentationwebhostingguy
 
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 Presentaionglslarmenta
 
Couchbase & FTS
Couchbase & FTSCouchbase & FTS
Couchbase & FTSRich Lee
 
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 APICaldera Labs
 
Getting Creative with WordPress Queries, Again
Getting Creative with WordPress Queries, AgainGetting Creative with WordPress Queries, Again
Getting Creative with WordPress Queries, AgainDrewAPicture
 
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 BrocatoSencha
 
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 PerformanceIvan Chepurnyi
 
Rails 3 Beautiful Code
Rails 3 Beautiful CodeRails 3 Beautiful Code
Rails 3 Beautiful CodeGreggPollack
 

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 ahiGABY220597
 
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 Schooltraderruss
 
Presentacion power point catedra
Presentacion power point catedraPresentacion power point catedra
Presentacion power point catedraDimelza 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 RoleJohanna 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 DevsDiacode
 
Oracle Endeca Developer's Guide
Oracle Endeca Developer's GuideOracle Endeca Developer's Guide
Oracle Endeca Developer's GuideKeyur Shah
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
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 2RORLAB
 
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 DevelopersKathy Brown
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second LanguageRob 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 CDavid Wheeler
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 
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 PHPSanju Sony Kurian
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)Beau Lebens
 

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 packagePaul 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 JobPaul Graham
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServerPaul Graham
 
Adding disqus to ghost blog
Adding disqus to ghost blogAdding disqus to ghost blog
Adding disqus to ghost blogPaul Graham
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage ReportsPaul Graham
 
Entity framework (EF) 7
Entity framework (EF) 7Entity framework (EF) 7
Entity framework (EF) 7Paul Graham
 
Code syntax highlighting in ghost
Code syntax highlighting in ghostCode syntax highlighting in ghost
Code syntax highlighting in ghostPaul 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

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

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