473,837 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Word Mail Merging

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.Applicatio n wrdApp;
Word._Document wrdDoc;
Object oMissing = System.Reflecti on.Missing.Valu e;
Object oFalse = false;

private void FillRow(Word._D ocument 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.Insert After(Text1);
oDoc.Tables[1].Cell(Row, 2).Range.Insert After(Text2);
oDoc.Tables[1].Cell(Row, 3).Range.Insert After(Text3);
oDoc.Tables[1].Cell(Row, 4).Range.Insert After(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
7 4171

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.Ite m(1).Cell instead of oDoc.Tables[1].Cell

Mar 23 '07 #2
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.Ite m(1).Cell instead of oDoc.Tables[1].Cell
Mar 23 '07 #3
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***@discussi ons.microsoft.c omwrote in message
news:AF******** *************** ***********@mic rosoft.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.Applicatio n wrdApp;
Word._Document wrdDoc;
Object oMissing = System.Reflecti on.Missing.Valu e;
Object oFalse = false;

private void FillRow(Word._D ocument 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.Insert After(Text1);
oDoc.Tables[1].Cell(Row, 2).Range.Insert After(Text2);
oDoc.Tables[1].Cell(Row, 3).Range.Insert After(Text3);
oDoc.Tables[1].Cell(Row, 4).Range.Insert After(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
guy
On Fri, 23 Mar 2007 23:51:51 -0700, "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <St***@Orr.ne t>
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
"guy" <gu*@hotmail.co mwrote in message
news:6e******** *************** *********@4ax.c om...
>>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
guy
On Sat, 24 Mar 2007 12:27:15 -0000, "Mark Rae" <ma**@markNOSPA Mrae.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
"guy" <gu*@hotmail.co mwrote in message
news:ug******** *************** *********@4ax.c om...
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2075
by: Dan Nash | last post by:
Hi guys I wonder if you could help. I'm trying to create a bespoke interface for mail merging from an Access database in Word. At the moment, I'm just trying it with CSV files, and it works. Word loads, data gets pasted in and it merges fine. One problem tho, it's doing Form Letters rather than Mailing Labels Here's the code...
1
3171
by: Morris | last post by:
Does anyone know whether it is possible to effect a mail merge to MSWord using VBScript in an asp file? I know it is possible to produce a doc file and force a download using Response.ContentType = "application/msword" Response.AddHeader content-disposition","attachment;filename=myfile.doc" but can I interate through a bunch of records and produce, say, a separate invoice for each one by merging? I know how to iterate through the...
4
8883
by: Tom Dauria | last post by:
I have an application that will be distributed remotely. In the Access application I am opening Word documents and mail merging. The Word documents are linked to a tmpLetter table. In my code I write the records to be merged into that table. The Word documents are using a system dsn (ODBC) to connect to the data source. In my code I simply open the Word documents after writing to the table do a mail merge and print. It runs pretty...
5
4048
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I think - it might have been XP) to 2003. The database is impressive, both in what it does and the obtuse and inconsistent ways it works. There are several hundred queries, for example, with no indication of where they are used or if they are in fact...
1
4966
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word 1. Query..I want to keep the fields seperatred. I do not want to sent on field with all accumulated languages from one person to Word. Each language should appear in the document in a separate cell Cross tables are not delivering the result I...
1
1695
by: jason301 | last post by:
I have started to get a problem when mail merging from my access database to word. When I mail merge the database password is requested to proceed which is odd as the database is already open. If I enter the password then the mail merge will fail. However if I click cancel when asked for the password the mail merge will work but then the database will close. I am continually working on this database and changing things which must mean...
1
1507
by: David Costello | last post by:
Hi, I'm creating a program to do some mail merging, and I need to delete some white space that is before the text of the second page on my mail merging letter. Does anyone know a good way of ensuring the input cursor is placed on the first line of the second page of a read-in document? I've got a small version of what I need working as a stand alone application, using the Word Document browser commands. In the full mail merging program I'm...
6
4655
by: crealesmith | last post by:
Firstly, I have no problem with mail merging to Word, VB code for that works perfectly. On one mail merge I need to merge 15 fields of data that are from 3 seperate records. The 3 records are all in the same table. If I use a control source that is selecting the 3 records, all of the data is shown but spread over 3 pages in the mail merge, but needs to be listed together in one paragraph. Is there anyway of looping through the 3...
7
7246
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking for any comments about the use of the docmd.transfertext method instead of the code Albert used for creating the text file. Also, perhaps some ideas for coding the Subject Line of each email so
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10886
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10277
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5674
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.