<?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>DevtheWeb.NET &#187; OpenXML</title>
	<atom:link href="http://www.devtheweb.net/blog/tag/openxml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devtheweb.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 06 Dec 2011 19:25:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Export data to docx file using Open XML SDK</title>
		<link>http://www.devtheweb.net/blog/2010/02/08/export-data-to-docx-file-using-open-xml-sdk/</link>
		<comments>http://www.devtheweb.net/blog/2010/02/08/export-data-to-docx-file-using-open-xml-sdk/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 10:46:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[OpenXML]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=913</guid>
		<description><![CDATA[Here&#8217;s simple example how can we export some table data to docx file using Open XML SDK. If you are not familiar with Open XML SDK, you can check out first Introduction to Open XML SDK. In this example: 1) Create some string array that represent table data 2) Create a new Docx file and [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s simple example how can we export some table data to docx file using Open XML SDK. If you are not familiar with Open XML SDK, you can check out first <a href="http://www.devtheweb.net/blog/2010/01/11/introduction-to-open-xml-sdk-2-0/" target="_blank">Introduction to Open XML SDK</a>.</p>
<p>In this example:<br />
1) Create some string array that represent table data<br />
2) Create a new Docx file and init it<br />
3) Create styles for the table and fill it with data<br />
4) Fill the table with data<br />
5) Add the table to the document and save the changes</p>
<p>//t some data to export in table<br />
string[][] data = {new string[]{&#8220;column 1&#8243;, &#8220;column 2&#8243;, &#8220;column 3&#8243;, &#8220;column 4&#8243;, &#8220;column 5&#8243;},<br />
new string[]{&#8220;A&#8221;, &#8220;B&#8221;, &#8220;C&#8221;, &#8220;D&#8221;, &#8220;E&#8221;},<br />
new string[]{&#8220;1&#8243;, &#8220;2&#8243;, &#8220;3&#8243;, &#8220;4&#8243;, &#8220;5&#8243;},<br />
new string[]{&#8220;Dev&#8221;, &#8220;The&#8221;, &#8220;Web&#8221;, &#8220;dot&#8221;, &#8220;NET&#8221;}<br />
};</p>
<p>/*t create and init a new docx file and<br />
a WordprocessingDocument object to represent it t*/<br />
WordprocessingDocument doc = WordprocessingDocument.Create(&#8220;E:\dox-export.docx&#8221;,<br />
WordprocessingDocumentType.Document);</p>
<p>MainDocumentPart mainDocPart = doc.AddMainDocumentPart();<br />
mainDocPart.Document = new Document();<br />
Body body = new Body();<br />
mainDocPart.Document.Append(body);</p>
<p>/*t init the cell border styles t*/<br />
TableCellProperties cellProperties = new TableCellProperties(<br />
new TableCellBorders<br />
{<br />
TopBorder = new TopBorder<br />
{<br />
Val = new EnumValue&lt;BorderValues&gt;(BorderValues.BasicBlackDots),<br />
Size = new UInt32Value((uint)8),<br />
Color = new StringValue(&#8220;000000&#8243;)<br />
},<br />
RightBorder = new RightBorder<br />
{<br />
Val = new EnumValue&lt;BorderValues&gt;(BorderValues.BasicBlackDots),<br />
Size = new UInt32Value((uint)8),<br />
Color = new StringValue(&#8220;000000&#8243;)<br />
},<br />
BottomBorder = new BottomBorder<br />
{<br />
Val = new EnumValue&lt;BorderValues&gt;(BorderValues.BasicBlackDots),<br />
Size = new UInt32Value((uint)8),<br />
Color = new StringValue(&#8220;000000&#8243;)<br />
},<br />
LeftBorder = new LeftBorder<br />
{<br />
Val = new EnumValue&lt;BorderValues&gt;(BorderValues.BasicBlackDots),<br />
Size = new UInt32Value((uint)8),<br />
Color = new StringValue(&#8220;000000&#8243;)<br />
},<br />
});</p>
<p>/*t fill the string[][] data into<br />
DocumentFormat.OpenXml.Wordprocessing.Table object t*/</p>
<p>Table table = new Table();<br />
for (int i = 0; i &lt; data.Length; ++i)<br />
{<br />
TableRow row = new TableRow();</p>
<p>for (int j = 0; j &lt; data[i].Length; ++j)<br />
{<br />
TableCell cell = new TableCell(cellProperties.Clone() as TableCellProperties);</p>
<p>cell.Append(new Paragraph(<br />
new Run(<br />
new Text(data[i][j])<br />
)));</p>
<p>row.Append(cell);<br />
}</p>
<p>table.Append(row);<br />
}</p>
<p>/*t add some info about the dox export t*/<br />
body.Append(new Paragraph(<br />
new Run(<br />
new Text(&#8220;Table exported by DevTheWeb.NET&#8221;)<br />
)));</p>
<p>body.Append(table);<br />
<!--adsense--><br />
/*t don&#8217;t forget to save your changes t*/<br />
doc.MainDocumentPart.Document.Save();<br />
doc.Dispose();</p>
<p>That&#8217;s all, if we open the dox file, we can see the exported table:<br />
<a href="http://www.devtheweb.net/blog/wp-content/uploads/2010/02/export-data-to-docx.png" rel="lightbox[913]"><img class="alignnone size-full wp-image-915" title="export-data-to-docx" src="http://www.devtheweb.net/blog/wp-content/uploads/2010/02/export-data-to-docx.png" alt="" width="400" height="402" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/02/08/export-data-to-docx-file-using-open-xml-sdk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Open XML SDK 2.0</title>
		<link>http://www.devtheweb.net/blog/2010/01/11/introduction-to-open-xml-sdk-2-0/</link>
		<comments>http://www.devtheweb.net/blog/2010/01/11/introduction-to-open-xml-sdk-2-0/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 08:22:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[OpenXML]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=493</guid>
		<description><![CDATA[Currently, I work with Open XML SDK 2.0 and in this post, I&#8217;ll try to explain simple introduction to it: What is Open XML and Open XML SDK? Open XML is an open standard that defines a set of XML schemas for representing spreadsheets, presentations, charts and word processing documents. Microsoft Office 2007 applications (Word, [...]]]></description>
			<content:encoded><![CDATA[<p>Currently, I work with Open XML SDK 2.0 and in this post, I&#8217;ll try to explain simple introduction to it:</p>
<p><strong>What is Open XML and Open XML SDK?</strong></p>
<p>Open XML is an open standard that defines a set of XML schemas for representing spreadsheets, presentations, charts and word processing documents. Microsoft Office 2007 applications (Word, Excel and PowerPoint) use the Open XML as the default file format. The Open XML file formats are based on ZIP and XML.</p>
<div><!--adsense--></div>
<p>The Open XML SDK 2.0 provides classes to manipulate Open XML documents. The Open XML SDK 2.0 uses the LINQ (Language-Integrated Query) technology to provide strongly typed object access to the XML content inside the parts of the Open XML documents.</p>
<p><strong>Download and Install<br />
</strong><br />
You can download Open XML SDK 2.0 <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&amp;displaylang=en" target="_blank">HERE</a>.</p>
<p>System Requirements:</p>
<ul>
<li>OS: Windows 7; Windows Server 2003 SP 2; Windows Server 2008 R2; Windows Server 2008 SP 2; Windows Vista SP 2; Windows XP SP 3</li>
<li>.NET Framework version 3.5 SP1</li>
<li>At least 300 MB available disk space</li>
</ul>
<p><strong>Using the Open XML API 2.0 in Visual Studio 2008 Project</strong></p>
<p>To use the API in your Visual Studio project, all you need to do is to add Reference to DocumentFormat.OpenXml:</p>
<p>In Solution Explorer, right-click References and select Add Reference.</p>
<p>In the dialog box, select .NET tab and select DocumentFormat.OpenXml option and then click OK.</p>
<p><a href="http://www.devtheweb.net/blog/wp-content/uploads/2010/01/add-openxml-reference.png" rel="lightbox[493]"><img class="alignnone size-full wp-image-495" title="add-openxml-reference" src="http://www.devtheweb.net/blog/wp-content/uploads/2010/01/add-openxml-reference.png" alt="" width="416" height="352" /></a></p>
<p><strong>Read Docx&#8217;s Text</strong></p>
<p>It&#8217;s very easy to read the text of Word 2007 Document file, here&#8217;s an example:</p>
<p>using System.IO;<br />
using DocumentFormat.OpenXml;<br />
using DocumentFormat.OpenXml.Packaging;</p>
<p>//t local variables<br />
WordprocessingDocument doc;<br />
string result = &#8220;&#8221;;</p>
<p>try<br />
{<br />
//t load the .docx document<br />
doc = WordprocessingDocument.Open(stringForFilePath, false);</p>
<p>result = (doc.MainDocumentPart.Document).Body.InnerText;<br />
}<br />
catch (Exception ex)<br />
{<br />
//t handle the exception<br />
}</p>
<p>return result;</p>
<p><strong>Conclusion</strong><br />
At first look it seems to be easy to work with the Open XML 2.0 SDK, it&#8217;s easy to install use in Visual Studio 2008. I created a simple program that loads text from docx file:<br />
<a href="http://www.devtheweb.net/blog/wp-content/uploads/2010/01/openxml-sdk-introduction.png" rel="lightbox[493]"><img class="alignnone size-full wp-image-537" title="openxml-sdk-introduction" src="http://www.devtheweb.net/blog/wp-content/uploads/2010/01/openxml-sdk-introduction.png" alt="" width="400" height="270" /></a></p>
<p>You can download it <a href="http://www.devtheweb.net/downloads/TestOpenXmlSdk.rar">HERE</a>.</p>
<form id="formPoll" method="post" action="http://www.devtheweb.net/polls/poll-do-you-find-microsoft-openxml-sdk-useful.aspx?embed=true#vote">
<p><strong>Do you find Microsoft OpenXML SDK useful?</strong></p>
<div>&nbsp;</div>
<div>
<input value="option1" id="option1" type="radio" name="poll" /><label for="option1">Yes, it&#8217;s great</label></div>
<div>
<input value="option2" id="option2" type="radio" name="poll" /><label for="option2">Maybe</label></div>
<div>
<input value="option3" id="option3" type="radio" name="poll" /><label for="option3">No, total waste of time</label></div>
<div>
<input value="option4" id="option4" type="radio" name="poll" /><label for="option4">I don&#8217;t know</label></div>
<div>&nbsp;</div>
<div>
<input type="submit" value="VOTE" onclick="this.form.target='_blank';return true;" /></div>
<div>&nbsp;</div>
<p><a href="http://www.devtheweb.net/polls/poll-do-you-find-microsoft-openxml-sdk-useful.aspx#results" target="_blank">View Results</a></p>
</form>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/01/11/introduction-to-open-xml-sdk-2-0/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

