word table clear formatting

D

Devhead

i am trying to insert a string into a table cell. i am getting some extra
characters like escape characters and the last character in the string i am
trying to insert. weird. i agree. for example if my string(s) is Chris
Burns, if i put a watch on tc.Range.Text i am seeing "Chris Burnss\r\a" and
it shows up in the table cell as "Chris Burnss". notice the extra character
at the end of the name. I want to clear out the table cell, remove all
characters, then insert the string s into the cell position. what am i doing
wrong here? thanks.


here is my code:

//table cell text/field placement

private static void StringtoCell(string s, Word.Cell tc)

{

tc.Range.Text = s;

}
 
J

Jim Vierra

Somewhere your string is getting clobbered in the C# app. Look at all
string declarations. Try s.ToString() when sending but I don't think this
is where it is being clobbered.

Is your declaration like this? "String s = "Some Name";"

If it's on the stack it can get clobbered pretty easily in a function call
if anything is declared wrong or not initialized.

The watch look like it is overlaying another string. Look for other strings
either declared or read in that may be overwriting something.

I'm not real sure with C# but I believe all strings declared as such are on
the heap so something may be happening there.

Another question I would as is what se a string with "s\r\a". It looks
like formatting from the document.
 
D

Devhead

the s string is fine. the table cell contains these characters and when i
try to overwrite the cell with s, the characters aren't getting cleared out
but appended to end of s string.
 
J

Jim Vierra

Oh - I didn't understand that. How did those characters get into the Cell?

My experience with building VB or C# access to Excel is that it is possible
to corrupt the Excel sheet. Did you try starting with a new workbook?
 
D

Devhead

it is not excel. it is a word table. i don't understand why the word table
cell value cannot be overwritten with table.cell(row,col).range.text = "some
string". it is placing the string in front of any characters already
present. if i set the table.cell(row,col).range.text = "", i see the extra
character in question.
 
J

Jim Vierra

Sorry - I have been trying to delve out what could be going wrong. I keep
coming back to corrupt document or code/data overrun or some change to the
document in you code that is corrupting the document structure.

Check for all service packs on Word including any referenced by knowledge
base articles.

Try commenting out all code that changes the document except the offending
line. Start with a brand new document and manually add the elements you
need for testing.

Hope this helps.
 
C

Cindy M -WordMVP-

Hi Devhead,

All tables contain two characters at the end of a cell Range: Chr(13) and
Chr(7), a paragraph mark and an end-of-cell marker. You must explicitly trim
these off the string...
i am trying to insert a string into a table cell. i am getting some extra
characters like escape characters and the last character in the string i am
trying to insert. weird. i agree. for example if my string(s) is Chris
Burns, if i put a watch on tc.Range.Text i am seeing "Chris Burnss\r\a" and
it shows up in the table cell as "Chris Burnss". notice the extra character
at the end of the name. I want to clear out the table cell, remove all
characters, then insert the string s into the cell position. what am i doing
wrong here? thanks.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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