<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Development in a Blink &#187; Open Xml</title>
	<atom:link href="http://www.dougfinke.com/blog/index.php/category/open-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dougfinke.com/blog</link>
	<description>Researching the optimal; implementing the practical</description>
	<lastBuildDate>Tue, 07 Sep 2010 00:22:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>.Net 3.0, PowerShell and Scott Hanselman</title>
		<link>http://www.dougfinke.com/blog/index.php/2008/07/02/net-30-powershell-and-scott-hanselman/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=net-30-powershell-and-scott-hanselman</link>
		<comments>http://www.dougfinke.com/blog/index.php/2008/07/02/net-30-powershell-and-scott-hanselman/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 01:41:00 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Open Xml]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://dougfinke.com/blog/?p=445</guid>
		<description><![CDATA[Scott posted Back to Basics: var != Dim showing how to use Microsoft Office Interop to change a value in the CustomDocumentProperties of a Word document. My Approach Use PowerShell and System.IO.Packaging in Windowbase.dll from .Net 3.0. Advantages Microsoft Office does not need to be installed Works with Word, Excel and PowerPoint It is not [...]]]></description>
			<content:encoded><![CDATA[<p>Scott posted <a href="http://www.hanselman.com/blog/BackToBasicsVarDim.aspx">Back to Basics: var != Dim</a> showing how to use Microsoft Office Interop to change a value in the CustomDocumentProperties of a Word document.</p>
<h3>My Approach</h3>
<p>Use PowerShell and <em>System.IO.Packaging</em> in Windowbase.dll from .Net 3.0.</p>
<h5>Advantages</h5>
<ul>
<li>Microsoft Office <em><strong>does not </strong></em>need to be installed </li>
<li>Works with Word, Excel and PowerPoint </li>
<li>It is not limited to just custom properties&#160; </li>
<li>Only a text editor is needed to write the glue </li>
</ul>
<p>I wrote the PowerShell Package dll which facilitates the transition between PowerShell and the Packaging namespace. </p>
<h3>Process</h3>
<p>Office 2007 files are zip files. Take an Excel file, rename it to .zip and unzip it. Check out the file system directory structure and contents. It is all Xml. The System.IO.Packaging namespace let&rsquo;s you work with compressed file contents, package parts, relationships and the data stream.</p>
<p>The DLL and PowerShell scripts abstract this further. The <em>Support.ps1 </em>script<em> </em>contains functions and filters which wrap the C# DLL so the methods play better in PowerShell&rsquo;s pipeline.</p>
<p>The <em>Update-Properties.ps1 </em>script pipes through the relationships, relationship types, target uri&rsquo;s and retrieves the document object model. The nested for each statements extract all the custom properties, sets them and finally saves and closes the document.</p>
<h3>Summary</h3>
<p>This code forms the basis for next steps in modifying the data in Office documents.&#160; Recently I joined the open source project <a href="http://www.codeplex.com/PowerTools">PowerTools for Open XML</a> and found a script written by <a href="http://blogs.msdn.com/dglover/archive/2007/06/28/powershell-and-office-open-xml-format-document-generation.aspx">Dave Glover</a> which sparked this approach.</p>
<p>Dave demonstrated how to generate Office Open Xml documents on the fly by merging a Word Template with an Xml file of Customers into customer invoices. </p>
<p>His script generates 80 documents/second. After making it more PowerShell like I generated 140 documents/second. Refactoring can improve this another 30%.</p>
<p>In subsequent posts I will improve this code and demonstrate other ways to interact with Office Open Xml.</p>
<h3>The Code</h3>
<pre>param(<span style="color: #35687d">$file</span>=<span style="color: maroon">&quot;.\Template.docx&quot;</span>)

. .\Support

(Open-Package <span style="color: #35687d">$file</span>).Relationships |
  <span style="color: blue">Where</span> {<span style="color: #35687d">$_</span>.RelationshipType -match <span style="color: maroon">'custom-properties'</span>} |
    <span style="color: blue">ForEach</span> {<span style="color: #35687d">$_</span>.TargetUri} |
      Get-Dom |
        <span style="color: blue">ForEach</span> { <span style="color: #35687d">$_</span>.Properties.property } |
          <span style="color: blue">ForEach</span> {<span style="color: #35687d">$_</span>.lpwstr=<span style="color: maroon">&quot;TestChange&quot;</span>}

Save-Package
Close-Package</pre>
<h3>Download</h3>
<p>The Standalone.zip contains test documents, PowerShell scripts and the compiled DLL. The other zip contains the VS 2008 solution as well.</p>
<p><iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 26px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-5dec3b62d9308943.skydrive.live.com/embedrow.aspx/PowerShellPackage/Standalone.zip" frameborder="0" scrolling="no"></iframe><iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 26px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-5dec3b62d9308943.skydrive.live.com/embedrow.aspx/PowerShellPackage/PowerShellPackageLibary.zip" frameborder="0" scrolling="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2008/07/02/net-30-powershell-and-scott-hanselman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Xml meet PowerShell</title>
		<link>http://www.dougfinke.com/blog/index.php/2008/06/18/open-xml-meet-powershell/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=open-xml-meet-powershell</link>
		<comments>http://www.dougfinke.com/blog/index.php/2008/06/18/open-xml-meet-powershell/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 00:24:13 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Open Xml]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerTools]]></category>

		<guid isPermaLink="false">http://dougfinke.com/blog/?p=433</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft announced a fully supported release of the Open XML Format SDK 1.0, read about it <a href="http://blogs.msdn.com/erikaehrli/archive/2008/06/10/announcing-the-open-xml-format-sdk-1-0.aspx">here</a> download it <a href="http://go.microsoft.com/fwlink/?LinkId=120908">here</a>. </p>
<p>Eric White, Technical Evangelist for Open XML, <a href="http://blogs.msdn.com/ericwhite/archive/2008/06/11/processing-open-xml-documents-server-side-using-powershell.aspx">announced</a> an open source project for processing Open Xml documents using PowerShell, <a href="http://www.codeplex.com/PowerTools">PowerTools for Open XML</a>.</p>
</p>
<h3>I offered my help</h3>
</p>
<p>I emailed Eric, offered my help and he added me as a developer.</p>
<h3>PowerTools for Open XML</h3>
<p>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.</p>
<p>I&rsquo;ve gone through some of the code and scripts, made some changes and reworked the BulkMailing.ps1 example into the ImprovedBulkMailing.ps1 script.</p>
<h3>Improved Bulk Mailing</h3>
<p>In a nutshell, the script reads an Xml file, dumped from the Northwind customers database, containing customer name, address etc.</p>
<p>The script uses the inline letter and&#160; generates 88 separate Word documents customized to each customer.</p>
<p>Download the updated script <a href="http://www.codeplex.com/PowerTools/Release/ProjectReleases.aspx?ReleaseId=14307">here</a>.</p>
<h3>Excel</h3>
<p>Creating a an Excel spreadsheet of the running processes on your system is as simple as</p>
<pre><span style="color: #2b91af">Get-Process</span> |
  Export-OpenXmlSpreadsheet .\<span style="color: #2b91af">ps</span>.xlsx</pre>
<p>Creating a spreadsheet and separate chart of the top 10 memory consumers</p>
<pre><span style="color: #2b91af">Get-Process</span> |
 <span style="color: #2b91af">sort</span> -Descending PM |
  <span style="color: #2b91af">select</span> name, PM -First <span style="color: maroon">10</span> |
   Export-OpenXmlSpreadsheet .\<span style="color: #2b91af">ps</span>.xlsx `
    -Chart -ChartType bar `
    -ColumnsToChart PM -HeaderColumn Name</pre>
<h3>Next Steps</h3>
<p>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.</p>
<p><a href="http://www.codeplex.com/PowerTools">Check it out</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2008/06/18/open-xml-meet-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
