Creating a word document (docx) from a word template (dotx)

  • Thread starter Dimitris Dierickx
  • Start date
D

Dimitris Dierickx

Hi,

I'm trying to create a word 2007 document from a certain template (.dotx)
which has several content controls on it. These content controls need to be
filled out with text from textboxes from a windows form.

I have been searching on word 2007 automation but I didn't find much.

Can someone help me by giving good articles or even some code?
 
C

Cindy M.

Hi Dimitriys,
I'm trying to create a word 2007 document from a certain template (.dotx)
which has several content controls on it. These content controls need to be
filled out with text from textboxes from a windows form.

I have been searching on word 2007 automation but I didn't find much.

Can someone help me by giving good articles or even some code?
The first thing you need to figure out is how you want to identify the content
controls. While they have a "Title" property, the title property is not a
unique identifier, so can't be used as an indexer. Valid indexers are either
the location in the document (in the collection) or the ID property (an
arbitrary number assigned by Word when the control is created).

Otherwise, if you want to use the Title property (or some other property) to
locate a Content Control in the collection you need to loop through the entire
collection, testing that property's value.

Assigning the content to the content control is simple enough:
objContentControl.Range.Text = "my string of text"

An alternate approach is to use the new OpenXML file format. You can use XSLT
on the template before opening it to populate the content.

Another method would be to create a CustomXML Part in the template, map it to
the Content Controls, then manipulate just this Custom XML Part when creating
the document.

Further resources:

http://blogs.msdn.com/modonovan/archive/2006/05/23/604704.aspx

http://msdn2.microsoft.com/en-us/library/ms406053.aspx

openxmldeveloper.org

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi =?Utf-8?B?RGltaXRyaXM=?=,
Yes, this is an alternate approach, working directly with the OpenXML. Good article, hadn't come across that
one :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by
e-mail :)
 
N

naokotakahasi

Try to use Spire.Doc (http://www.e-iceblue.com/Introduce/word-for-net-introduce.html) - it is .NET component that supports read and write doc, docx, html, image etc. embed image still support.



Dimitris Dierick wrote:

Creating a word document (docx) from a word template (dotx)
01-Jun-07

Hi,

I'm trying to create a word 2007 document from a certain template (.dotx)
which has several content controls on it. These content controls need to be
filled out with text from textboxes from a windows form.

I have been searching on word 2007 automation but I didn't find much.

Can someone help me by giving good articles or even some code?

Previous Posts In This Thread:

Creating a word document (docx) from a word template (dotx)
Hi,

I'm trying to create a word 2007 document from a certain template (.dotx)
which has several content controls on it. These content controls need to be
filled out with text from textboxes from a windows form.

I have been searching on word 2007 automation but I didn't find much.

Can someone help me by giving good articles or even some code?

Hi Dimitriys,The first thing you need to figure out is how you want to
Hi Dimitriys,

The first thing you need to figure out is how you want to identify the content
controls. While they have a "Title" property, the title property is not a
unique identifier, so can't be used as an indexer. Valid indexers are either
the location in the document (in the collection) or the ID property (an
arbitrary number assigned by Word when the control is created).

Otherwise, if you want to use the Title property (or some other property) to
locate a Content Control in the collection you need to loop through the entire
collection, testing that property's value.

Assigning the content to the content control is simple enough:
objContentControl.Range.Text = "my string of text"

An alternate approach is to use the new OpenXML file format. You can use XSLT
on the template before opening it to populate the content.

Another method would be to create a CustomXML Part in the template, map it to
the Content Controls, then manipulate just this Custom XML Part when creating
the document.

Further resources:

http://blogs.msdn.com/modonovan/archive/2006/05/23/604704.aspx

http://msdn2.microsoft.com/en-us/library/ms406053.aspx

openxmldeveloper.org

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)

Re: Creating a word document (docx) from a word template (dotx)
Hi,

Thanks for your answer but I found another method.

http://www.microsoft.com/france/msd...-un-document-Word-a-partir-d-un-Template.mspx

The article is in french though but it helped me out a great deal.

Hi =?Utf-8?B?RGltaXRyaXM=?
Hi =?Utf-8?B?RGltaXRyaXM=?=,

Yes, this is an alternate approach, working directly with the OpenXML. Good article, hadn't come across that
one :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by
e-mail :)


Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk: Parallel Processing with Correlation
http://www.eggheadcafe.com/tutorial...alk-parallel-processing-with-correlation.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top