Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Mail Merge problems. | Microsoft Word Help | |||
Mail merge problems | New Users | |||
Mail Merge Problems | New Users | |||
encoding problems in Word 2002 | Microsoft Word Help | |||
Mail merge e-mail character encoding | Mailmerge |