1

I created a Shared AddIn using Visual Studio 2008, C#. In the AddIn, I get data from a database, populate it into a Dictionary object, and use Word's builtin FindReplace to replace text inside a WordTemplate with the data from the database.

  Dictionary<string, string> myDBData = new Dictionary<string, string>();

Some of the db fields need the newline character (i.e. multi-line data), so I insert a newline using Environment.NewLine in my code before passing the dictionary object to a find-replace routine.

The problem is, for fields that have the newline character in them, the text is getting replaced properly inside the world template only if the [replacemefieldname] placeholder is outside a Word Table like so.

These 12 lines are outside A MS WORD Table:

Firm

Firm

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

If the [replacemefieldname] placeholder is inside a MS Word Table, the the multiple text string is rendering in a single line like so.

Firm Firm Fluid Fluid Fluid Fluid Fluid Fluid Fluid Fluid Fluid Fluid

See following screenshot for both rendering (inside and outside table).

If I copy the table text and paste outside, then also the new lines render properly!!

So what other characters besides Environment.NewLine should I be placing in between the lines in the string before passing it on to Word to do find-replace for [replacemefieldname] placeholders that exist inside a MS Word Table ?

thank you

ps. The clever folks at StackOverflow are preventing me from posting screenshot since I'm deemed a "New User", so here is the screenshot that makes my question clearer.. :)

http://img231.imageshack.us/img231/144/wrderr.png

Shiva
  • 20,575
  • 14
  • 82
  • 112
  • See that pilcrow button (the paragraph symbol) in the Ribbon? Click that and post another screen shot. – Todd Main Jun 23 '10 at 03:42
  • Is this the screen shot you are asking for ? http://img19.imageshack.us/img19/2750/wrderrwithspecialchars.png It shows the special characters. Note that it does not show the newline characters in the text inside the table cell, however, if I simply copy cell contents using control+C and paste using Control+V, viola! the text is rendered with the newLine. baffling. – Shiva Jun 24 '10 at 01:51
  • Here is an actual Test Word Document, with the content (inside table, outside table) for you to check out and help... http://mycodetrip.com/Table-Issue-WordDoc.docx thank you – Shiva Jun 25 '10 at 18:36

0 Answers0