By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Word Mail Merging

P: n/a
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

Mar 23 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a

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

Mar 23 '07 #2

P: n/a
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
Mar 23 '07 #3

P: n/a
The technique you are using (COM interop with Office) is not recommended for
use with ASP.NET, as explained here by Microsoft:
http://support.microsoft.com/default...;EN-US;q257757

There are some good 3rd party products that would probably be better
options.
Here are a couple that should work:
http://SteveOrr.net/reviews/AsposeWord.aspx
http://SteveOrr.net/reviews/OfficeWriter.aspx

VSTO should also work:
http://msdn2.microsoft.com/en-us/office/aa905533.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net


"Badis" <Ba***@discussions.microsoft.comwrote in message
news:AF**********************************@microsof t.com...
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
Mar 24 '07 #4

P: n/a
guy
On Fri, 23 Mar 2007 23:51:51 -0700, "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <St***@Orr.net>
wrote:
>The technique you are using (COM interop with Office) is not recommended for
use with ASP.NET, as explained here by Microsoft:
http://support.microsoft.com/default...;EN-US;q257757
<snip>

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

Is there a asp.net example of client-side mail merge?

Like this sample using asp
http://support.microsoft.com/default...;EN-US;q285176
Mar 24 '07 #5

P: n/a
"guy" <gu*@hotmail.comwrote in message
news:6e********************************@4ax.com...
>>The technique you are using (COM interop with Office) is not recommended
for
use with ASP.NET, as explained here by Microsoft:
http://support.microsoft.com/default...;EN-US;q257757
<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...;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...
Mar 24 '07 #6

P: n/a
guy
On Sat, 24 Mar 2007 12:27:15 -0000, "Mark Rae" <ma**@markNOSPAMrae.comwrote:
<snip>
>
>Is there a asp.net example of client-side mail merge?

Like this sample using asp
http://support.microsoft.com/default...;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...
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?
Mar 24 '07 #7

P: n/a
"guy" <gu*@hotmail.comwrote in message
news:ug********************************@4ax.com...
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.
Mar 24 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.