Mail Merge w/ HTML Data Source (Word 2003)

J

Jan - LundK

Hello,

I'd like to do a mail merge using word. Some of my fields have a length of
1000 characters but get truncated after 315 characters.
I'm using a html file as data source (Data is stored in a Table)
The mail merge is executed by a C# COM-AddIn and uses the Office 2003 PIAs.
Everything works fine except for the truncated fields.

Anyone has a tip for me?

Here's a part of the source code:

...
Microsoft.Office.Interop.Word.MailMerge mm = wordDoc.MailMerge; // wordDoc
is a function parameter, the type is Microsoft.Office.Interop.Word.Document

object omissing = System.Reflection.Missing.Value;
String Source = "c:\test.html";
object Format =
Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatWebPages;
object ConfirmConversions = false;
object ReadOnly = false;
object LinkToSource = false;
object AddToRecentFiles = false;
object PasswordDocument = "";
object PasswordTemplate = "";
object Revert = false;
object WritePasswordDocument = "";
object WritePasswordTemplate = "";
object Connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
DataFileName + ";Mode=Read;Extended Properties=\"HTML Import;HDR=YES;\"";
object SQLStatement = "SELECT * FROM `table` ";
object SQLStatement1 = "";
object OpenExclusive = false;
object SubType =
Microsoft.Office.Interop.Word.WdMergeSubType.wdMergeSubTypeOLEDBText;
object objFalse = false;


// DocumentType is passed as parameter
mm.MainDocumentType = docType;

#region OpenDataSource
mm.OpenDataSource(
Source,
ref Format,
ref ConfirmConversions,
ref ReadOnly,
ref LinkToSource,
ref AddToRecentFiles,
ref PasswordDocument,
ref PasswordTemplate,
ref Revert,
ref WritePasswordDocument,
ref WritePasswordTemplate,
ref Connection,
ref SQLStatement,
ref SQLStatement1,
ref OpenExclusive,
ref SubType);

#endregion

mm.SuppressBlankLines = true;

// Fields are replaced by data
mm.ViewMailMergeFieldCodes = 0;
wordApp.ScreenUpdating = false;
mm.Execute(ref omissing);
...

Thanks
jan
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?SmFuIC0gTHVuZEs=?=,
I'd like to do a mail merge using word. Some of my fields have a length of
1000 characters but get truncated after 315 characters.
I'm using a html file as data source (Data is stored in a Table)
The mail merge is executed by a C# COM-AddIn and uses the Office 2003 PIAs.
Everything works fine except for the truncated fields.
Do some testing in the Word interface, first.

1. Do you see the truncation if you manually link to the data source and
execute the merge (to a new document)?

2. If yes, try opening the HTML in Word and save it as a Word document. Now
link to this and test again. Is the data still being truncated, or are all
the characters coming across?

3. If (2) works, then we're probably looking at a limitation of the OLE DB
connection method for JET. Then it's worth trying to force the use of Word's
internal file converter. Still in the Word UI, activate "Confirm conversions
on open" in Tools/Options/General. Link up to the HTML file. You should get a
dialog box listing the converters available for this data source type. Try
any and everything else listed other than OLE DB and see what works.

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 :)
 
J

Jan - LundK

Cindy M -WordMVP- said:
Hi =?Utf-8?B?SmFuIC0gTHVuZEs=?=,

Do some testing in the Word interface, first.

1. Do you see the truncation if you manually link to the data source and
execute the merge (to a new document)?

2. If yes, try opening the HTML in Word and save it as a Word document. Now
link to this and test again. Is the data still being truncated, or are all
the characters coming across?

3. If (2) works, then we're probably looking at a limitation of the OLE DB
connection method for JET. Then it's worth trying to force the use of Word's
internal file converter. Still in the Word UI, activate "Confirm conversions
on open" in Tools/Options/General. Link up to the HTML file. You should get a
dialog box listing the converters available for this data source type. Try
any and everything else listed other than OLE DB and see what works.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)


This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)

Hi Cindy,

thanks for the reply, your solution worked! Using another converter was the
solution.

A colleague tested it and modified the code like this:

....
object Format = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatAuto;
object ConfirmConversions = true;
object LinkToSource = true;
object Connection = "";
object SQLStatement = "";
object SubType =
Microsoft.Office.Interop.Word.WdMergeSubType.wdMergeSubTypeOther;
....

With this modification of the code from my first Post it worked.
In our german Word we used "Alle Webseiten" as converter.

BTW: We had another problem with word cutting off trailing zeros in our Data
Source, that is solved with your solution, too.
Even Microsoft Support couldn't help us with that. :)

Thanks again for your help,
jan
 

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