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
 
Database presentation
Database presentationDatabase presentation
Database presentation
webhostingguy
 
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 Lab
Colin Su
 

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 Esciting
armax
 
THE VILLAGE COUNTY NEW
THE VILLAGE COUNTY NEWTHE VILLAGE COUNTY NEW
THE VILLAGE COUNTY NEW
Raj Rajput
 
Ela Awasthi-NEW RESUME
Ela Awasthi-NEW RESUMEEla Awasthi-NEW RESUME
Ela Awasthi-NEW RESUME
Ela Awasthi
 

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-3
tutorialsruby
 
<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-3
tutorialsruby
 

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 (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

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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