Word Mail Merging

G

Guest

Hi,

I'm trying to follow a mail merging example in C#.Net that I got from:
http://support.microsoft.com/default.aspx/kb/301659
and in one the methods:

Word.Application wrdApp;
Word._Document wrdDoc;
Object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;

private void FillRow(Word._Document oDoc, int Row, string Text1,
string Text2, string Text3, string Text4)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row, 1).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell(Row, 2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell(Row, 3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell(Row, 4).Range.InsertAfter(Text4);
}

it's giving me this Error:
Cannot apply indexing with [] to an expression of type 'Word.Tables'
I'm not sure if Visual C# objects aren't the same as C#.Net !!?


Thanks
 
M

Muhammad Naveed Yaseen

You are probably using older word library than recommended for
your .NET version.

In any case at least the indexing error can be worked around by
referring as oDoc.Tables.Item(1).Cell instead of oDoc.Tables[1].Cell
 
M

Muhammad Naveed Yaseen

You are probably using older word library than recommended for
your .NET version.

In any case at least the indexing error can be worked around by
referring as oDoc.Tables.Item(1).Cell instead of oDoc.Tables[1].Cell
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

M

Mark Rae

<snip>

q257757 article states that MS does not recommend server-side automation
of Office

Not only doesn't recommend it, but won't actually support any solution which
uses it...
Is there a asp.net example of client-side mail merge?

Like this sample using asp
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q285176

That's just creating the merge file, not actually performing the mail
merge... At that level, ASP.NET is hardly any different from ASP Classic
i.e. creates a text file with the merge details which the user then
downloads onto their local environment and runs the mail merge manually...
 
M

Mark Rae

1. Maybe you can better explain what the following code in the sample is
doing then?

' Execute the mail merge.
.Execute

Apologies - I didn't make myself clear enough...

See the Summary paragrph right at the beginning of the article:

"This article demonstrates how to automate Microsoft Word 2000 and Microsoft
Office Word 2003 from client-side script to perform a mail merge for labels.
Word does not have a direct method for using XML data as the data source for
a mail merge. The sample illustrates Active Server Pages (ASP) code that
streams an XML recordset from a Web server to a client. Client-side script
converts this XML data to a delimited text file that is local to the client
and then automates Word to perform a mail merge by using the local text file
as the mail merge data source."

This is creating the merge document server-side, streaming it down to the
client browser and then running the mail-merge from there - it is not doing
the actual mail merge on the server. As I said, there is very little
difference in the way ASP Classic does client-side automation from the way
ASP.NET does it...

However, this should really only ever be considered in an enclosed
environment where

a) the client browser is IE - nothing else supports ActiveX

b) you can be certain that Word is installed on the clients' machine

c) you've ramped down the security far enough to actually allow this to work

2. Is there an updated asp.net version of q285176?

No.
 
G

guy

That's just creating the merge file, not actually performing the mail
merge... At that level, ASP.NET is hardly any different from ASP Classic
i.e. creates a text file with the merge details which the user then
downloads onto their local environment and runs the mail merge manually...

1. Maybe you can better explain what the following code in the sample is doing then?

' Execute the mail merge.
.Execute

2. Is there an updated asp.net version of q285176?
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top