Bonjour,

Voila ma problématique :
Je souhaite fusionner sous un même fichier word à partir d'un template les enregistrements présents dans un data reader. Voici une partie de mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
//*****************
                //  EXCEL
                //*****************
                if (System.IO.File.Exists(monFichier)) System.IO.File.Delete(monFichier);
 
                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                if (xlApp == null)
                {
                    Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");
                    return;
                }
                xlApp.Visible = false;
                Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                Worksheet ws = (Worksheet)wb.Worksheets[1];
            //*****************
            //  WORD
            //*****************
            //OBJECT OF MISSING "NULL VALUE"
            Object oMissing = System.Reflection.Missing.Value;
 
            //OBJECTS OF FALSE AND TRUE
            Object oTrue = true;
            Object oFalse = false;
 
            //CREATING OBJECTS OF WORD AND DOCUMENT
            Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
 
            //MAKING THE APPLICATION VISIBLE
            oWord.Visible = true;
 
            Object oTemplatePath = monModele;
 
            //ADDING A NEW DOCUMENT FROM A TEMPLATE
            oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
 
            myOleDbConnection.Open();
            OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
 
            int num = myOleDbDataReader.FieldCount;
            int i = 1;
 
            while (myOleDbDataReader.Read())
            {
                int j = 1;
 
                while (j < num + 2)//+2 pour ajouter les 2 dates saisies
                {
                    if (j < num)
                    {
                        ws.Cells[i, j] = myOleDbDataReader.GetValue(j);
                        foreach (Microsoft.Office.Interop.Word.Field myMergeField in oWordDoc.Fields)
                        {
                            //iTotalFields++;
                            Microsoft.Office.Interop.Word.Range rngFieldCode = myMergeField.Code;
                            String fieldText = rngFieldCode.Text;
 
                            // ONLY GETTING THE MAILMERGE FIELDS
                            if (fieldText.StartsWith(" MERGEFIELD"))
                            {
                                String fieldName = fieldText.Substring(11, fieldText.Length - 11);
                                fieldName = fieldName.Trim();
                                if (fieldName == myOleDbDataReader.GetName(j))
                                {
                                    myMergeField.Select();
                                    oWord.Selection.TypeText("pour voir");
                                }
                            }
                        }
                    }
                    else if (j == num)
                    {
                        ws.Cells[i, j] = dReleve.Text;
                    }
                    else if (j == num + 1)
                    {
                        ws.Cells[i, j] = dEnvoi.Text;
                    }
                    j++;
                }
 
                object oEndOfDoc = "\\endofdoc";
                object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
                oWordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertBreak(ref oPageBreak);
                i++;
            }
            myOleDbDataReader.Close();
Le pb est que je fusionne bien le premier enregistrement, mais pour les suivants j'obtiens une page blanche. Je ne peux pas créer un .doc pour chacun des enregistrements alors j'aimerais savoir comment procéder pour que mon template soit pris en compte pour chaque nouvelle page?