Tabel Cell range text problem

Z

zfeld

I am having a problem adding text to a cell in an existing table
it seems to be pre-appending my text to the current text as opposed to
overwriting which is what I need.

my code is in C#
cell = table.Cell(curRow, 1); // the first column

Word.Range cellRange = cell.Range; //cellrange =
cell.Range.Paragraphs.Item(1).Range; didn't either work

string dd = cellRange .Text; //dd - will show as "1\n\a" in the debugger

int currentBuilding = 5;

cellRange.Text = currentBuilding.ToString(); //replace the text with 5

dd = cellRange .Text; ////dd - will show as "51\n\a" in the debugger
 
M

Malcolm Smith

my code is in C#
cell = table.Cell(curRow, 1); // the first column

I am guessing that the problem may be here? cell is a class and you're
using it as an object.

How about:

oCell = table.Cell(curRow,1);

- Malc
 
Z

zfeld

lowercase cell is just my variable name. cell, oCell all the same thing. The
class name is uppercase Cell. It wouldn't compile if this was the problem.
That isn't my problem.
 
C

Cindy M -WordMVP-

Hi Zfeld,

Interesting. I would have expected this to work... A couple of observations
that may help you find the problem

1. When you pick up cell.range.text you should be getting not only the text
you can see in the cell, but in addition Chr$(13) + Chr$(7). This is
end-of-paragraph plus a end-of-cell markers. This could perhaps be
interfering with your code.

2. I have occasionally seen behavior such as you describe when the document
structure has been damaged. Mostly, I've seen it when trying to work with
ranges in the header/footer stories, but it's always turned out to be
internal structural problems. You might test the code on a table in a new
document.

3. Worst comes to worst: how about cell.range.delete before inserting the
new text?
I am having a problem adding text to a cell in an existing table
it seems to be pre-appending my text to the current text as opposed to
overwriting which is what I need.

my code is in C#
cell = table.Cell(curRow, 1); // the first column

Word.Range cellRange = cell.Range; //cellrange =
cell.Range.Paragraphs.Item(1).Range; didn't either work

string dd = cellRange .Text; //dd - will show as "1\n\a" in the debugger

int currentBuilding = 5;

cellRange.Text = currentBuilding.ToString(); //replace the text with 5

dd = cellRange .Text; ////dd - will show as "51\n\a" in the debugger

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