A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problems with mail merge (encoding)



 
 
Thread Tools Display Modes
  #1  
Old June 10th, 2009, 02:24 PM posted to microsoft.public.word.mailmerge.fields
Thierry Thoua
external usenet poster
 
Posts: 1
Default Problems with mail merge (encoding)

Hello,

I've a "little" problem with Word interop (Office 11). I'd like to
automate the mailmerge.... I've a word file and a .txt file (a csv).
The text file is in UTF-8 encoding.

This is my "code" :

this.document.MailMerge.MainDocumentType =
WdMailMergeMainDocType.wdFormLetters;
this.document.MailMerge.Destination =
WdMailMergeDestination.wdSendToNewDocument;
object subType = WdMergeSubType.wdMergeSubTypeOther;
object format = WdOpenFormat.wdOpenFormatUnicodeText;
object confirmConversions = false;
this.document.MailMerge.OpenDataSource(cheminFichi er, ref
format, ref confirmConversions, ref ComWrapper.OpenDocumentAsReadOnly,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref subType);

document.MailMerge.Execute(ref ComWrapper.Missing);
object index = 1;
_Document mailMergeResult = this.word.Documents.get_Item
(ref index);

It works fine ... BUT .. Sometimes when I load a lot my service ...
The word doesn't use the "utf-8" encoding ... Word use "Windows
standard (default)" = When I execute the mail merge ... I've a window
with a wrong key "ïMyKey" and not "MyKey" .... What's wrong ???

Do you have any idea ?

Thanks
  #2  
Old June 10th, 2009, 05:38 PM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default Problems with mail merge (encoding)

!. As far as I know, word takes little or notice of the format parameter
when opening Mail Merge Data Sources. Some other parameters that have an
effect when opening a Document via, e.g. Documents.Open are also ignored
in OpenDataSource. Mailmerge tends to use other methods to try to work
out what kind of file it is dealing with.

2. What is probably happening is that
a. The method Word is using to open the text file is deciding the
encoding is not UTF-8. That might, for example, be because there is a
DefaultCPG setting in the registry (have a look under
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\W ord\Options
). There could well be other reasons why the text converter is not
recognising UTF-8 correctly, but I do not know what they might be,.
b. If the UTF-8 file does not have a BOM (Byte Order Mark) at the
beginning, then the name of the first column may be correct
c. if the UTF-8 file has a BOM, then Word will treat the BOM as the
first few characters of th efirst column name (in whatever encoding it
is expecting)

That assumes that Word is opening the file using its text converter,
which is what I /think/ your code will do (it's as if you were doing

OpenDataSource name:="the text file.txt"

) and if you are seeing the encoding dialog box that is almost certainly
what it is doing.

3. See if that leads anywhere first. Otherwise, it may be possible to
force Word to use UTF-8 encoding, but only if the OLE DB text provider
can read your files (maybe not if they have multiline texts or more than
255/256 columns), and you are in a position to create/maintain a couple
of other files.

Peter Jamieson

http://tips.pjmsn.me.uk

Thierry Thoua wrote:
Hello,

I've a "little" problem with Word interop (Office 11). I'd like to
automate the mailmerge.... I've a word file and a .txt file (a csv).
The text file is in UTF-8 encoding.

This is my "code" :

this.document.MailMerge.MainDocumentType =
WdMailMergeMainDocType.wdFormLetters;
this.document.MailMerge.Destination =
WdMailMergeDestination.wdSendToNewDocument;
object subType = WdMergeSubType.wdMergeSubTypeOther;
object format = WdOpenFormat.wdOpenFormatUnicodeText;
object confirmConversions = false;
this.document.MailMerge.OpenDataSource(cheminFichi er, ref
format, ref confirmConversions, ref ComWrapper.OpenDocumentAsReadOnly,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref subType);

document.MailMerge.Execute(ref ComWrapper.Missing);
object index = 1;
_Document mailMergeResult = this.word.Documents.get_Item
(ref index);

It works fine ... BUT .. Sometimes when I load a lot my service ...
The word doesn't use the "utf-8" encoding ... Word use "Windows
standard (default)" = When I execute the mail merge ... I've a window
with a wrong key "ïMyKey" and not "MyKey" .... What's wrong ???

Do you have any idea ?

Thanks

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:18 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.