Bonjour
Je veux ecrire au niveau d'un fichier Word et voici 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
 
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.IO;
using System.Drawing;
using safaqat.Entities;
using safaqat.Data;
using Word1 = Microsoft.Office.Interop.Word;
using Gios.Word;
using System.Text;
using GCOM;
using System.Diagnostics;
using file;
 
public partial class Admin_CPS_LireFichierXML : System.Web.UI.Page
{
 
    public Word1.Document objdoc = new Microsoft.Office.Interop.Word.Document();
    public Word1.Document objdoc1 = new Microsoft.Office.Interop.Word.Document();
    public Word1.Application objWord = new Microsoft.Office.Interop.Word.Application();
 
    public int wordProcessID = 0;
    public int[] listAv = null, ListAp = null;
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
 
 
    public void SearchAndReplace(string sMotParam, string sMotValeur)
    {
 
 
        Object unit = Word1.WdUnits.wdStory;
        Object extend = Word1.WdMovementType.wdMove;
 
 
//Prb
 
        this.objWord.Selection.HomeKey(ref unit, ref extend);
        Word1.Find fnd = this.objWord.Selection.Find;
        fnd.ClearFormatting();
        fnd.Text = sMotParam;
        fnd.Replacement.ClearFormatting();
        fnd.Replacement.Highlight = 0;
        fnd.Replacement.Text = sMotValeur;
        if (sMotParam.Contains("@") == false)
            fnd.MatchWildcards = true;
        ExecuteReplace(fnd);
 
    }
 
 
 
 
    protected void Button2_Click(object sender, EventArgs e)
 
    {
 
        string Filename = "fichier.doc";
 
 
        string chemin = HttpContext.Current.Request.MapPath("MonDossier\\");
 
 
        chemin = chemin + Filename;
        NouveauDocument(chemin);
        string cheminFile = "C:\\model.doc";
 
        if (Label1.Text != "")
        {
            SearchAndReplace("@objet1","test1");
 
        }
        else
            SearchAndReplace("@objet1", " ");
 
        if (Label2.Text != "")
        {
            SearchAndReplace("@objet2", "test2";
        }
        else
            SearchAndReplace("@objet2", " ");
 
        objdoc1.Save();
 
     CloseDocument();
        closeWordAppli(wordProcessID);
        Label3.Text = "Génération ok ";
 
    }
}