![]() |
Enterprise Systems »
Office Development »
Microsoft Word
Intermediate
License: The Code Project Open License (CPOL)
Adding An Image to a Word Document Programmatically (Microsoft Office 2007)By Abey ThomasThis article is about the details of adding an image to a Word document programmatically. |
XML, C# 2.0, C# 3.0, Office, .NET 2.0, .NET 3.0, COM+, VS2008, Dev, Design
|
|
Advanced Search |
|
|
|
||||||||||||||||
This article is about the details of adding an image to a Word document programmatically.
Let us assume a sample document which contains an image placeholder with some tag value. For those who know how to add an image placeholder to a Word document, they can skip the next portion, and directly look at the implementation details.
ImagePlaceHolder1. I have uploaded a sample Word document with all this done. It can be found in the DocxImages\DocxImages\SampleTemplate folder.
Now this is just a place holder. Our requirement is to embed an image (of our choice) at run time to this place holder. The remaining part of the article deals with this issue.
Now we have the template Word document. Assume that we have an image file already. For the sake of simplicity, I am assuming a static image file which is already available with me. In real time scenarios, it can be dynamically created images like charts, etc.
I have placed both the template and the sample image in the programs bin/debug folder.
Before going into the implementation details, let me give you some fundamentals.
With what is said above, embedding an image on the fly is a very easy process. It can be summarized in three points:
XPathNodeIterator. The source code of the whole process is uploaded with this article and can be found here. Put the sample template document and the sample image in the bin/debug folder of the program, and execute it.
| You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Oct 2008 Editor: Deeksha Shenoy |
Copyright 2008 by Abey Thomas Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |