Open Xml meet PowerShell

by Doug Finke on June 18, 2008

in Open Xml,PowerShell,PowerTools

Microsoft announced a fully supported release of the Open XML Format SDK 1.0, read about it here download it here.

Eric White, Technical Evangelist for Open XML, announced an open source project for processing Open Xml documents using PowerShell, PowerTools for Open XML.

I offered my help

I emailed Eric, offered my help and he added me as a developer.

PowerTools for Open XML

Currently there are 33 PowerShell cmdlets. They work with Excel and Word creating and modifying files directly without the Office object model and do not require the installation of Microsoft Office.

I’ve gone through some of the code and scripts, made some changes and reworked the BulkMailing.ps1 example into the ImprovedBulkMailing.ps1 script.

Improved Bulk Mailing

In a nutshell, the script reads an Xml file, dumped from the Northwind customers database, containing customer name, address etc.

The script uses the inline letter and  generates 88 separate Word documents customized to each customer.

Download the updated script here.

Excel

Creating a an Excel spreadsheet of the running processes on your system is as simple as

Get-Process |
  Export-OpenXmlSpreadsheet .\ps.xlsx

Creating a spreadsheet and separate chart of the top 10 memory consumers

Get-Process |
 sort -Descending PM |
  select name, PM -First 10 |
   Export-OpenXmlSpreadsheet .\ps.xlsx `
    -Chart -ChartType bar `
    -ColumnsToChart PM -HeaderColumn Name

Next Steps

Eric and I have been chatting about several ideas. Improving the underlying PowerShell cmdlets, adding PowerPoint cmdlets, and other ways PowerShell can make short work of leveraging Open Xml.

Check it out.

{ 1 trackback }

Doug Mahugh : Open XML links for 06-22-2008
06.22.08 at 5:33 pm

{ 1 comment… read it below or add one }

Ben McInerney 02.26.09 at 5:38 pm

Hi Doug,

I have just come across this wonderful stuff – i am a massive supporter of PowerShell, and again its proved its worth ala OpenXML.

However, if you are keen to add another commandlet – please add one that allows this:

Add-OpenXMLDocument “main.docx” “child.docx”

This grabs the contents of the child doc ($child.MainDocumentPart) and inserts it into $main.MainDocumentPart.

It may be simple – i am very tired at the moment – but i cant seem to crack it.
(not much doco on using AddNewPart using PowerShell)

Cheers,
Ben

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>