SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

<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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Kürzlich hochgeladen (20)

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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

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