Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Tables / July 2004

Tip: Looking for answers? Try searching our database.

Using ConvertToText to create tables containing cells with embedded new line characters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mystery Man - 27 Jul 2004 05:14 GMT
We use Word 2000 and 2003 automation from C# (via interop). We create
tables dynamically. However, we now need to have embedded returns
within a cell.

For example:-

Row 1: Date     Text
Row 2: 1/1/2002 Help me
               please
Row 3: 1/1/2004 Help me

Sample code is as follows:-

object rows = 3;
object columns = 3;

string text = "Date\tText\t1/1/2002\tHelp me\nplease\t1/1/2004\tHelp
me";

Word.Range range = _wordApp.Selection.Range;
range.Text = tableValue.ToString();

Word.Table newTable = range.ConvertToTable(ref sep    // Separator
,ref numRows    // NumRows
,ref numColumns    // NumColumns
,ref oMissing    // InitialColumnWidth
,ref oMissing    // Format
,ref oMissing    // ApplyBorders
,ref oMissing    // ApplyShading
,ref oMissing    // ApplyFont
,ref oMissing    // ApplyColor
,ref oMissing    // ApplyHeadingRows
,ref oMissing    // ApplyLastRow
,ref oMissing    // ApplyFirstColumn
,ref oMissing    // ApplyLastColumn
,ref oMissing    // AutoFit
,ref oMissing    // AutoFitBehaviour
,ref oMissing    // DefaultTableBehaviour
);

However, what this does is create a new row when it encounters the \n.
I have tried using different column separators and a few other
possibilities but to no avail.
Klaus Linke - 27 Jul 2004 20:15 GMT
Hi mystery man,

You probably could wait until you have created the table, and only then change \n into paragraph marks.

I guess currently \n is changed into vbCr in the function .ToString?
You could either take the conversion of "\n" out of that function, or, if you don't want to change it because it's used elsewhere, immediately replace vbCr back into some placeholder ("\n" or whatever).

Regards,
Klaus
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.