Building Word documents using C#

A

Andrew Mercer

Hi,

I am building a word document using C# and Word .NET Programmability however
I have a question that I cannot find the answer for.

I have designed the Word template with embedded bookmarks.

When I build the document I dynamically place text at each book mark position.

The base document also has some other fixed text in it.

However in the completed document the original text is always moved.

EG:

Original document

MyText More MyText

Completed document

MyText [C# Added Text] More MyText

It seems that the original text is moved along a number of tab spaces
depending on the size of the text being added.

Is there anyway to prevent this so that the layout of the completed document
is the
same as the original (the only difference is the added text)?

I know that the spaces I left in the template are sufficient for the text I
want to add.

Any help/advice greatly appreciated.

Regards Andrew
 
C

Cindy M.

Hi Andrew,

I think there's a misconception on your part about how Word documents
function...

If you add spaces between some text, then push more text in-between, the spaces
aren't removed.

You could use a two-column table to achieve the layout you describe.
You could set a left-aligned tabstop at the position of the second "column",
then press TAB at the end of the text in the first "column" (removing all the
spaces that are currently there)
You could place the text in the second "column" in a text box or a frame from
the Forms toolbar.

Which option to use depends very much on the end-use of the document. I suggest
you experiment a bit with these in the Word UI to determine which best meets
your needs.
I am building a word document using C# and Word .NET Programmability however
I have a question that I cannot find the answer for.

I have designed the Word template with embedded bookmarks.

When I build the document I dynamically place text at each book mark position.

The base document also has some other fixed text in it.

However in the completed document the original text is always moved.

EG:

Original document

MyText More MyText

Completed document

MyText [C# Added Text] More MyText

It seems that the original text is moved along a number of tab spaces
depending on the size of the text being added.

Is there anyway to prevent this so that the layout of the completed document
is the
same as the original (the only difference is the added text)?

I know that the spaces I left in the template are sufficient for the text I
want to add.

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 :)
 
A

Andrew Mercer

Hi,

Thanks - I was assuming (or perhaps hoping) that adding text at a bookmark
would overwrite the spaces rather than move them forwards.

I did think about trying to replace the text - however I assume this
requires replacing the correct number of empty spaces as well.

Thanks Again

Andrew

--
Andrew Mercer
-----------------


Cindy M. said:
Hi Andrew,

I think there's a misconception on your part about how Word documents
function...

If you add spaces between some text, then push more text in-between, the spaces
aren't removed.

You could use a two-column table to achieve the layout you describe.
You could set a left-aligned tabstop at the position of the second "column",
then press TAB at the end of the text in the first "column" (removing all the
spaces that are currently there)
You could place the text in the second "column" in a text box or a frame from
the Forms toolbar.

Which option to use depends very much on the end-use of the document. I suggest
you experiment a bit with these in the Word UI to determine which best meets
your needs.
I am building a word document using C# and Word .NET Programmability however
I have a question that I cannot find the answer for.

I have designed the Word template with embedded bookmarks.

When I build the document I dynamically place text at each book mark position.

The base document also has some other fixed text in it.

However in the completed document the original text is always moved.

EG:

Original document

MyText More MyText

Completed document

MyText [C# Added Text] More MyText

It seems that the original text is moved along a number of tab spaces
depending on the size of the text being added.

Is there anyway to prevent this so that the layout of the completed document
is the
same as the original (the only difference is the added text)?

I know that the spaces I left in the template are sufficient for the text I
want to add.

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


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?QW5kcmV3IE1lcmNlcg==?=,
Thanks - I was assuming (or perhaps hoping) that adding text at a bookmark
would overwrite the spaces rather than move them forwards.
I suppose it *might* be possible to do it the way you envision (although it's
an approach I would NEVER, EVER take or recommend):

In Tools/Options/Edit you should find a checkbox that allows "overtype". Try
activating that, then change your code to use

wdApp.Selection.Text = "abc"

If that test is successful, you can build the settings check, change AND
reinstatement (because most users will be pretty upset if you change this one
on them) into your code...

But, as I say, a "documentation professional" would never consider this route
for maintaining document layout :)

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 :)
 

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