Word Publipostage

fredspv Messages postés 127 Date d'inscription dimanche 7 mars 2004 Statut Membre Dernière intervention 6 juin 2008 - 16 juin 2005 à 22:14
the_surfer Messages postés 2 Date d'inscription mardi 23 décembre 2003 Statut Membre Dernière intervention 23 juillet 2007 - 23 juil. 2007 à 17:44
Bonjour,

Je veux faire un publipostage à l'aide d'un fichier TXT et de Word.

J'arrive à ouvrir le fichier Word mais il n'execute pas la fusion.

Voici le code principal.


Microsoft.Office.Interop.Word.ApplicationClass WordApp =
new Microsoft.Office.Interop.Word.ApplicationClass();



object fileName = "C:\\test.doc";



object readOnly =
false;



object isVisible =
true;



object missing = System.Reflection.Missing.Value;



object oMissing = System.Reflection.Missing.Value;


WordApp.Visible =
true;


Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(
ref fileName,
ref missing,
ref missing,



ref missing,
ref missing,
ref missing,
ref missing,
ref missing,



ref missing,
ref missing,
ref missing,
ref missing,
ref missing,



ref missing,
ref missing,
ref missing);


aDoc.MailMerge.OpenDataSource("C:\\test1.txt",
ref oMissing,
ref


oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref


oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);


aDoc.MailMerge.Execute(aDoc);

Merci de votre aide

fred

1 réponse

the_surfer Messages postés 2 Date d'inscription mardi 23 décembre 2003 Statut Membre Dernière intervention 23 juillet 2007
23 juil. 2007 à 17:44
En faite j'ai résolu le pb en mettant un macro AutoExec dans mon fichier Word qui se lance au demarrage.
Apres j'ai juste a ecrire le code suivant.

using

Word = Microsoft.Office.Interop.Word;

protected

void Button1_Click(
object sender,
EventArgs e){

Word.

Application oWord;

//System.Diagnostics.Process.Start("C:\\Program Files\\Microsoft Office\\Office11\\Winword.exe");System.Diagnostics.

Process.Start(
"G:\\DSI\\$Installations\\Logiciels\\D‚velopp‚s\\ASP.NET\\Gestion des actes\\Sources\\registre2.doc");oWord = (Word.

Application) System.Runtime.InteropServices.
Marshal.GetActiveObject(
"Word.Application");oWord = (Word.

Application) System.Runtime.InteropServices.
Marshal.GetActiveObject(
"Word.Application");

//MessageBox.Show(oWord.Name);

//Msgbox.Show(oWord.Name);oWord =

null; 

}

Laurent Orlando
Developpeur
0
Rejoignez-nous