<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Nishant Rana&#039;s Weblog &#187; Word InterOp</title>
	<atom:link href="http://nishantrana.wordpress.com/category/word-interop/feed/" rel="self" type="application/rss+xml" />
	<link>http://nishantrana.wordpress.com</link>
	<description>Everything related to Microsoft .NET technology</description>
	<lastBuildDate>Tue, 08 Dec 2009 09:08:15 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='nishantrana.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/7096194784cd6b5dc462bb0515e43296?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Nishant Rana&#039;s Weblog &#187; Word InterOp</title>
		<link>http://nishantrana.wordpress.com</link>
	</image>
			<item>
		<title>Setting Built In and Custom Document Properties using C#</title>
		<link>http://nishantrana.wordpress.com/2008/07/18/setting-built-in-and-custom-document-properties-using-c/</link>
		<comments>http://nishantrana.wordpress.com/2008/07/18/setting-built-in-and-custom-document-properties-using-c/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 10:36:36 +0000</pubDate>
		<dc:creator>Nishant Rana</dc:creator>
				<category><![CDATA[Word InterOp]]></category>

		<guid isPermaLink="false">http://nishantrana.wordpress.com/?p=137</guid>
		<description><![CDATA[Create a new windows application project and add a button to it.
On click of that button, we will open a document and add values for a built in and custom document properties.
Than add reference to (Word 10.0 or 11.0 object library) and Microsoft.Office.Core.dll within COM tab of Add reference dialog box.
After adding reference, add this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=137&subd=nishantrana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="font-size:11pt;">Create a new windows application project and add a button to it.</span></p>
<p><span style="font-size:11pt;">On click of that button, we will open a document and add values for a built in and custom document properties.</span></p>
<p><span style="font-size:11pt;">Than add reference to (Word 10.0 or 11.0 object library) and Microsoft.Office.Core.dll within COM tab of Add reference dialog box.</span></p>
<p><span style="font-size:11pt;">After adding reference, add this directive</span></p>
<p><em><strong><span style="font-size:11pt;">using Microsoft.Office.Interop.Word</span></strong></em></p>
<p><em><strong>using System.Reflection;</strong></em></p>
<p>Put the following code in the button click event handler</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// For optional parameters create a missing object</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> missing = System.Reflection.<span style="color:#008080;">Missing</span>.Value;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// Create an object for filename which is the file to be opened<span> </span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> fileName = <span style="color:#800000;">@&#8221;C:\MySecond.doc&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// Create an object of application class</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">ApplicationClass</span> WordApp = <span style="color:#0000ff;">new</span> <span style="color:#008080;">ApplicationClass</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// open the document specified in the fileName variable</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">Document</span> adoc = WordApp.Documents.Open(<span style="color:#0000ff;">ref</span> fileName, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// setting the document built in properties</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> oDocBuiltInProps = adoc.BuiltInDocumentProperties;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">Type</span> typeDocBuiltInProps = oDocBuiltInProps.GetType();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// setting the Title property with value &#8220;My Proposal&#8221;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">string</span> strIndex = <span style="color:#800000;">&#8220;Title&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">string</span> strValue = <span style="color:#800000;">&#8220;My Proposal&#8221;</span>;<span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">typeDocBuiltInProps.InvokeMember(<span style="color:#800000;">&#8220;Item&#8221;</span>,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">BindingFlags</span>.Default |</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">BindingFlags</span>.SetProperty,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">null</span>, oDocBuiltInProps,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">new</span> <span style="color:#0000ff;">object</span>[] { strIndex, strValue });</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// setting the custome document properties</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> oDocCustomProps = adoc.CustomDocumentProperties;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">Type</span> typeDocCustomProps = oDocCustomProps.GetType();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// setting the ProposalSentDate custom date property with current date time </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">string</span> strIndex1 = <span style="color:#800000;">&#8220;ProposalSentDate&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">string</span> strValue1 = <span style="color:#008080;">DateTime</span>.Now.ToShortDateString();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span>[] oArg = { strIndex1, <span style="color:#0000ff;">false</span>, Microsoft.Office.Core.<span style="color:#008080;">MsoDocProperties</span>.msoPropertyTypeDate, strValue1 };</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">typeDocCustomProps.InvokeMember(<span style="color:#800000;">&#8220;Add&#8221;</span>,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">BindingFlags</span>.Default |</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">BindingFlags</span>.InvokeMethod, <span style="color:#0000ff;">null</span>,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">oDocCustomProps,oArg);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"> </p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">WordApp.Visible = <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Byee&#8230;</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nishantrana.wordpress.com/137/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nishantrana.wordpress.com/137/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nishantrana.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nishantrana.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nishantrana.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nishantrana.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nishantrana.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nishantrana.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nishantrana.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nishantrana.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nishantrana.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nishantrana.wordpress.com/137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=137&subd=nishantrana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nishantrana.wordpress.com/2008/07/18/setting-built-in-and-custom-document-properties-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/110b603cfbecdae6ba10459409a7f1cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nishu</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating and Updating table of contents in word document using C#</title>
		<link>http://nishantrana.wordpress.com/2008/07/17/creating-and-updating-table-of-contents-in-word-document-using-c/</link>
		<comments>http://nishantrana.wordpress.com/2008/07/17/creating-and-updating-table-of-contents-in-word-document-using-c/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 16:18:34 +0000</pubDate>
		<dc:creator>Nishant Rana</dc:creator>
				<category><![CDATA[Word InterOp]]></category>

		<guid isPermaLink="false">http://nishantrana.wordpress.com/?p=128</guid>
		<description><![CDATA[   Create a new windows application project and add a button to it. 
On click of that button, we will open a document and first add a heading 1 programmatically and then insert a table of content programmatically and update it 
Than we will add reference to (Word 10.0 or 11.0 object library) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=128&subd=nishantrana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><!--[if gte mso 9]&gt;  Normal 0       MicrosoftInternetExplorer4  &lt;![endif]--> <!--[endif]--><!--  /* Font Definitions */  @font-face 	{font-family:"022022"; 	panose-1:0 0 0 0 0 0 0 0 0 0; 	mso-font-alt:"Times New Roman"; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-format:other; 	mso-font-pitch:auto; 	mso-font-signature:0 0 0 0 0 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} p 	{mso-margin-top-alt:auto; 	margin-right:0in; 	mso-margin-bottom-alt:auto; 	margin-left:0in; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --> <!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman";} --> <!--[endif]--><span style="font-size:10pt;">Create a new windows application project and add a button to it.</span> <span style="font-size:11pt;"></span></p>
<p><span style="font-size:11pt;"><span style="font-size:10pt;">On click of that button, we will open a document and first add a heading 1 programmatically and then</span></span> <span style="font-size:10pt;">insert a table of content programmatically and update it</span> <span style="font-size:11pt;"></span></p>
<p><span style="font-size:11pt;"><span style="font-size:10pt;">Than we will add reference to (Word 10.0 or 11.0 object library) within COM tab of Add reference dialog box.</span></span> <span style="font-size:11pt;"></span></p>
<p><span style="font-size:11pt;"><span style="font-size:10pt;">After adding reference, we’ll add this directive</span></span> <strong><span style="font-size:11pt;"><span style="font-size:10pt;">using Microsoft.Office.Interop.Word</span></span></strong> <span style="font-size:10pt;">than we’ll put the following code in the button click event handler</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">// For optional parameters create a missing object</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">object</span><span style="font-size:10pt;font-family:&quot;"> missing = System.Reflection.<span style="color:teal;">Missing</span>.Value;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">// Create an object for filename which is the file to be opened </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">object</span><span style="font-size:10pt;font-family:&quot;"> fileName = <span style="color:maroon;">@&#8221;C:\MySecond.doc&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">// Create an object of application class</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">ApplicationClass</span><span style="font-size:10pt;font-family:&quot;"> WordApp = <span style="color:blue;">new</span> <span style="color:teal;">ApplicationClass</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">// open the document specified in the fileName variable</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">Document</span><span style="font-size:10pt;font-family:&quot;"> adoc = WordApp.Documents.Open(<span style="color:blue;">ref</span> fileName, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing,</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">ref</span><span style="font-size:10pt;font-family:&quot;"> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing,</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">ref</span><span style="font-size:10pt;font-family:&quot;"> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">Range</span><span style="font-size:10pt;font-family:&quot;"> myRange = adoc.Range(<span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">myRange.InsertAfter(<span style="color:maroon;">&#8220;Hello Mickey Mouse GG &#8220;</span>);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">object</span><span style="font-size:10pt;font-family:&quot;"> oStyleName = <span style="color:maroon;">&#8220;Heading 1&#8243;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">myRange.set_Style(<span style="color:blue;">ref</span> oStyleName);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">object</span><span style="font-size:10pt;font-family:&quot;"> start=WordApp.ActiveDocument.Content.End &#8211; 1;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">Range</span><span style="font-size:10pt;font-family:&quot;"> rangeForTOC = adoc.Range(<span style="color:blue;">ref</span> start, <span style="color:blue;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">TableOfContents</span><span style="font-size:10pt;font-family:&quot;"> toc=adoc.TablesOfContents.Add(rangeForTOC, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing,<span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">toc.Update();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">Range</span><span style="font-size:10pt;font-family:&quot;"> rngTOC = toc.Range;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">rngTOC.Font.Size = 10;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">rngTOC.Font.Name = <span style="color:maroon;">&#8220;</span></span><span style="font-size:10pt;font-family:&quot;">Georgia</span><span style="font-size:10pt;font-family:&quot;">&#8220;</span><span style="font-size:10pt;font-family:&quot;">;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">WordApp.Visible = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;">Bye&#8230;</p>
<p class="MsoNormal">
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nishantrana.wordpress.com/128/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nishantrana.wordpress.com/128/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nishantrana.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nishantrana.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nishantrana.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nishantrana.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nishantrana.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nishantrana.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nishantrana.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nishantrana.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nishantrana.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nishantrana.wordpress.com/128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=128&subd=nishantrana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nishantrana.wordpress.com/2008/07/17/creating-and-updating-table-of-contents-in-word-document-using-c/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/110b603cfbecdae6ba10459409a7f1cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nishu</media:title>
		</media:content>
	</item>
		<item>
		<title>Opening and inserting a picture in word document programmatically using C#</title>
		<link>http://nishantrana.wordpress.com/2008/07/17/opening-and-inserting-a-picture-in-word-document-programmatically-using-c/</link>
		<comments>http://nishantrana.wordpress.com/2008/07/17/opening-and-inserting-a-picture-in-word-document-programmatically-using-c/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 13:40:40 +0000</pubDate>
		<dc:creator>Nishant Rana</dc:creator>
				<category><![CDATA[Word InterOp]]></category>

		<guid isPermaLink="false">http://nishantrana.wordpress.com/?p=125</guid>
		<description><![CDATA[Create a new windows application project and add a button to it.
On click of that button, we will open a document and insert a picture to it.
(In the doc file insert a table at the location where you want the picture to appear.)
Than add reference to (Word 10.0 or 11.0 object library) within COM tab [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=125&subd=nishantrana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="font-size:11pt;font-family:&quot;">Create a new windows application project and add a button to it.</span></p>
<p><span style="font-size:11pt;font-family:&quot;">On click of that button, we will open a document and insert a picture to it.</span></p>
<p><span style="font-size:11pt;font-family:&quot;">(</span><span style="font-size:11pt;font-family:&quot;">In the doc file insert a table at the location where you want the picture to appear.)</span></p>
<p><span style="font-size:11pt;font-family:&quot;">Than add reference to (Word 10.0 or 11.0 object library) within COM tab of Add reference dialog box.</span></p>
<p><span style="font-size:11pt;font-family:&quot;">After adding reference, add this directive</span></p>
<p><span class="mceitemhidden"><strong><span style="font-size:11pt;font-family:&quot;">using Microsoft.Office.</span></strong></span><span class="mceitemhiddenspellword"><strong><span style="font-size:11pt;font-family:&quot;">Interop</span></strong></span><span class="mceitemhidden"><strong><span style="font-size:11pt;font-family:&quot;">.Word</span></strong></span></p>
<p>Put the following code in the button click event handler</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// For optional parameters create a missing object</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#0000ff;">object</span> missing = System.Reflection.<span style="color:#008080;">Missing</span>.Value;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// Create an object for filename, which is the file to be opened </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#0000ff;">object</span> fileName=<span style="color:#800000;">@&#8221;C:\MySecond.doc&#8221;</span>; </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// Create an object of application class</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008080;">ApplicationClass</span> WordApp = <span style="color:#0000ff;">new</span> <span style="color:#008080;">ApplicationClass</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// open the document specified in the fileName variable</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008080;">Document</span> adoc = WordApp.Documents.Open(<span style="color:#0000ff;">ref</span> fileName, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// We can insert the picture using Range objects AddPicture method</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// To insert a picture at a particular location in the word document</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// insert a table over there and then refer that location through range object</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008080;">Range</span> rngPic = adoc.Tables[1].Range; </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">// we can even select a particular cell in the table </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;"><span style="color:#008000;">//Range rngPic = rng.Tables[1].Cell(2, 3).Range;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;">rngPic.InlineShapes.AddPicture(<span style="color:#800000;">@&#8221;C:\anne_hathaway.jpg&#8221;</span>, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-family:&quot;">WordApp.Visible = <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"> </p>
<p><span class="mceitemhidden"><strong></strong></span></p>
<p><span style="font-size:11pt;font-family:&quot;">Bye<br />
</span></p>
<p class="MsoNormal"> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nishantrana.wordpress.com/125/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nishantrana.wordpress.com/125/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nishantrana.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nishantrana.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nishantrana.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nishantrana.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nishantrana.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nishantrana.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nishantrana.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nishantrana.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nishantrana.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nishantrana.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=125&subd=nishantrana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nishantrana.wordpress.com/2008/07/17/opening-and-inserting-a-picture-in-word-document-programmatically-using-c/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/110b603cfbecdae6ba10459409a7f1cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nishu</media:title>
		</media:content>
	</item>
		<item>
		<title>Inserting or appending document or file in a word document programmatically using C#</title>
		<link>http://nishantrana.wordpress.com/2008/07/17/inserting-or-appending-document-or-file-in-a-word-document-programmatically-using-c/</link>
		<comments>http://nishantrana.wordpress.com/2008/07/17/inserting-or-appending-document-or-file-in-a-word-document-programmatically-using-c/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 12:29:25 +0000</pubDate>
		<dc:creator>Nishant Rana</dc:creator>
				<category><![CDATA[Word InterOp]]></category>

		<guid isPermaLink="false">http://nishantrana.wordpress.com/?p=122</guid>
		<description><![CDATA[Create a new windows application project and add a button to it.
On click of that button, we will create a new document and append or insert content of two documents in it.
First add reference to (Word 10.0 or 11.0 object library) within COM tab of Add reference dialog box.
After adding reference, add this directive
using Microsoft.Office.Interop.Word
Put [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=122&subd=nishantrana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Create a new windows application project and add a button to it.</p>
<p>On click of that button, we will create a new document and append or insert content of two documents in it.</p>
<p>First add reference to (Word 10.0 or 11.0 object library) within COM tab of Add reference dialog box.</p>
<p>After adding reference, add this directive</p>
<p><strong>using Microsoft.Office.Interop.Word</strong></p>
<p>Put this code on button click</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">// For optional parameters create a missing object</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> missing = System.Reflection.<span style="color:#008080;">Missing</span>.Value;</span> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// Create an object of application class</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">ApplicationClass</span> WordApp = <span style="color:#0000ff;">new</span> <span style="color:#008080;">ApplicationClass</span>();<span> </span></span> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// add a document in the Application </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">Document</span> adoc=WordApp.Documents.Add(<span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing);</span> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// declare variables for setting the position within the document</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> start = 0;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> end = 0;</span> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// create a range object which starts at 0</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">Range</span> rng = adoc.Range(<span style="color:#0000ff;">ref</span> start, <span style="color:#0000ff;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// insert a file </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">rng.InsertFile(<span style="color:#800000;">@&#8221;C:\MyFirst.doc&#8221;</span>, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// now make start to point to the end of the content of the first document</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">start = WordApp.ActiveDocument.Content.End &#8211; 1;</span> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// create another range object with the new value for start</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008080;">Range</span> rng1 = adoc.Range(<span style="color:#0000ff;">ref</span> start, <span style="color:#0000ff;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// insert the another document</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">rng1.InsertFile(<span style="color:#800000;">@&#8221;C:\MySecond.doc&#8221;</span>, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing, <span style="color:#0000ff;">ref</span> missing);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// now make start to point to the end of the content of the first document<span> </span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">start = WordApp.ActiveDocument.Content.End &#8211; 1;</span> </p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#008000;">// make the word appliction visible</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">WordApp.Visible = <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal"> </p>
<p><strong><span style="color:#0000ff;"><strong>Bye<br />
</strong></span></strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nishantrana.wordpress.com/122/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nishantrana.wordpress.com/122/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nishantrana.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nishantrana.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nishantrana.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nishantrana.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nishantrana.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nishantrana.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nishantrana.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nishantrana.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nishantrana.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nishantrana.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=122&subd=nishantrana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nishantrana.wordpress.com/2008/07/17/inserting-or-appending-document-or-file-in-a-word-document-programmatically-using-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/110b603cfbecdae6ba10459409a7f1cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nishu</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating Word document using C#</title>
		<link>http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/</link>
		<comments>http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 07:19:47 +0000</pubDate>
		<dc:creator>Nishant Rana</dc:creator>
				<category><![CDATA[Windows Application]]></category>
		<category><![CDATA[Word InterOp]]></category>

		<guid isPermaLink="false">http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/</guid>
		<description><![CDATA[Create a new windows application project and add a button to it.
On click of that button, we will create a new document(word) and write a simple Hello World text in it.
To create a word document using C# we need to first reference the following DLL(com)

After adding reference, add this directive
using Microsoft.Office.Interop.Word; 
Put this code on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=70&subd=nishantrana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Create a new windows application project and add a button to it.</p>
<p>On click of that button, we will create a new document(word) and write a simple Hello World text in it.</p>
<p>To create a word document using C# we need to first reference the following DLL(com)</p>
<p><img src="http://nishantrana.files.wordpress.com/2007/11/n.jpg" alt="DLL" /></p>
<p>After adding reference, add this directive</p>
<p><span style="color:#0000ff;"><strong>using Microsoft.Office.Interop.Word; </strong></span></p>
<p>Put this code on button click</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">void</span> button1_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">object</span> missing = System.Reflection.<span style="color:#2b91af;">Missing</span>.Value;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">object</span> Visible=<span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">object</span> start1 = 0;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">object</span> end1 = 0;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">ApplicationClass</span> WordApp = <span style="color:blue;">new</span> <span style="color:#2b91af;">ApplicationClass</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">Document</span> adoc = WordApp.Documents.Add(<span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">Range</span> rng = adoc.Range(<span style="color:blue;">ref</span> start1, <span style="color:blue;">ref</span> missing);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">try</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{<span>               </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>rng.Font.Name = <span style="color:#a31515;">&#8220;Georgia&#8221;</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>rng.InsertAfter(<span style="color:#a31515;">&#8220;Hello World!&#8221;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">object</span> filename = <span style="color:#a31515;">@&#8221;D:\MyWord.doc&#8221;</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>adoc.SaveAs(<span style="color:blue;">ref</span> filename, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing,</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing, <span style="color:blue;">ref</span> missing);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>WordApp.Visible = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:#2b91af;">MessageBox</span>.Show(ex.Message);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}<span>         </span></span></p>
<p class="MsoNormal" style="text-align:justify;margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:#333333;">The easiest way to write code for office interoperability is to make use of VBA code.</span></p>
<p><span style="color:#333333;">Say you want to insert a picture in a word document what you can do is </span></p>
<p><span style="color:#333333;">open the word document &#8211; Go to Tools -&gt;Macro-&gt; Record New Macro </span></p>
<p><span style="color:#333333;">Now click on insert menu and insert the picture. Stop the recording, again go to Macro -Macros-&gt; Select your Macro and click on edit</span></p>
<p>You will find the vba code over there</p>
<p><span style="color:#0000ff;">Sub Macro1()</span></p>
<p>Selection.InlineShapes.AddPicture FileName:= _<br />
&#8220;C:\Documents and Settings\nishantr1\My Documents\My Pictures\untitled.bmp&#8221; _<br />
, LinkToFile:=False, SaveWithDocument:=True<br />
End Sub</p>
<p><span style="color:#0000ff;"><span style="color:#333333;">Now to write the same code in c# you will do something like this</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="color:#0000ff;"><span style="font-family:&quot;">Range rngPic = adoc.Tables[1].Range;</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="color:#0000ff;"><span style="font-family:&quot;">rngPic.InlineShapes.AddPicture(@”C:\anne_hathaway.jpg”, ref missing, ref missing, ref missing);</span></span></p>
<p><strong>Bye</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nishantrana.wordpress.com/70/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nishantrana.wordpress.com/70/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nishantrana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nishantrana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nishantrana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nishantrana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nishantrana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nishantrana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nishantrana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nishantrana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nishantrana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nishantrana.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nishantrana.wordpress.com&blog=1794554&post=70&subd=nishantrana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/110b603cfbecdae6ba10459409a7f1cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nishu</media:title>
		</media:content>

		<media:content url="http://nishantrana.files.wordpress.com/2007/11/n.jpg" medium="image">
			<media:title type="html">DLL</media:title>
		</media:content>
	</item>
	</channel>
</rss>