IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

pré remplissage document word


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    49
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2010
    Messages : 49
    Par défaut pré remplissage document word
    bonjour à tous,

    je créé une application en asp.net VB sous visual studio et je souhaite pré-remplir certaine partie d'un document word via mon application.

    suite aux recherches que j'ai réalisées j'ai trouvé des tutoriel en langage c le probleme et que je ne maitrise pas ce langage. j'aimerai trouver une solution en langage vb.

    y a t'il une personne qui peut m'aider s'il vous plait ?

    cordialement.

  2. #2
    Membre émérite Avatar de methylene
    Profil pro
    Inscrit en
    Février 2010
    Messages
    659
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2010
    Messages : 659
    Par défaut
    Salut,

    Cherche du coté de la bibliothèque system.IO

    avec les commandes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Getfile
    File.ReadallLines
    File.OpenText
    File.OpenRead
    File.OpenWrite
    etc ...

    Bonne chance

  3. #3
    Membre averti
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    49
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2010
    Messages : 49
    Par défaut
    merci methylene, peut tu me donner plus de renseigner sur cela car je suis vraiment perdu, je n'arrete pas de chercher des tuto sur la toile mieu je n'ai rien trouvé en vb.net.

    cordialement

  4. #4
    Membre émérite Avatar de methylene
    Profil pro
    Inscrit en
    Février 2010
    Messages
    659
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2010
    Messages : 659
    Par défaut
    Regarde sur google avec System.IO()

    http://msdn.microsoft.com/fr-fr/libr...le(VS.80).aspx

    Dans ce lien ça parle des fichiers texte mais je suis quasi sur que tu peux adapter au fichier word.

    Ou encore le lien msdn de System.IO()

    http://msdn.microsoft.com/fr-fr/libr...(v=VS.80).aspx

    Zaloeillement votre,

    methylene.

  5. #5
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2010
    Messages
    291
    Détails du profil
    Informations personnelles :
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 291
    Par défaut
    Bonjour,

    Pour ma part j'utilise la chose suivante:

    J'ai créé un modèle de document sous Word (*.dotx), dans le quel j'ai créé des BookMark aux endroits où je veux insérer des données via VB.

    Dans mon projet VB.NET j'ai ajouté les références :
    Microsoft.office.Core
    Microsoft.Office.Interop.Word
    Microsoft.Office.Tools.Word.v9.0

    Dans le code ça donne ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Dim AppWord As New Microsoft.Office.Interop.Word.Application
                    Dim w As Microsoft.Office.Interop.Word.Document = AppWord.Documents.Add("P:\Dossiers\ModeleAR2.dotx")
                    w.Bookmarks("Titre").Range.Text = titre
                    w.Bookmarks("Prenom").Range.Text = Prenom
                    w.Bookmarks("Nom").Range.Text = Nom
                    w.Bookmarks("AdresseLigne1").Range.Text = AdresseLigne1
                    w.Bookmarks("Codepostal").Range.Text = Codepostal
                    w.Bookmarks("Ville").Range.Text = Ville
                    w.Bookmarks("Datecourrier").Range.Text =Format(datereception, "dd/mm/yyyy")
     
     
                    Dim cl = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges
                    w.SaveAs("P:\Courrierjuridique\" & DMEC.Nom & "\AR_" & DMEC.Nom & ".docx")

    A+

  6. #6
    Membre averti
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    49
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2010
    Messages : 49
    Par défaut reponse
    merci pour votre aide, je vais etre plus explicite en vous resumant mon probleme.
    je suis en cour de création d'une application web concernant les suivi des plan de prevention dans une entreprise.

    sous visual studio j'ai une page qui s'appelle document.aspx
    incluant un module document.ascx , dans cette page l'utilisateur choisi son document, soit un document model "pres rempli" soit une page vierge.

    concernant le document model je souhaite que lors de l'ouverture de ce document, les differentes données correspondant au plan de prevention soit deja rempli dans le document. cela permettra une saisie plus rapide.

    j'ai commencé a realiser ce que je voulais, en effet lorsque l'utilisateur choisi le model, le document s'ouvre et s'enregistre avec le numero du plan de prevention dans un repertoire, ce qui permet d'avoir par exemple "PDP-FR435" ainsi dans un repertoire j'ai tout les plan de prevention.

    concernant le script que GEO2A je ne sait pas ou le mettre quelqu'un peut t'il me renseigner sur cela s'il vous plait ?


    voici le code de mon module Document :
    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
     
    <script
        language="VBscript"
        type="text/vbscript">
     
      Sub ouvrir(lien)
        Set objShell = CreateObject("Wscript.Shell")
        objShell.run "" & lien & ""
      end sub
     
    </script>
     
    <asp:Label
        ID="LabelType"
        runat="server"
        Visible="False" />
    <asp:Label
        ID="LabelPrefixe"
        runat="server"
        Visible="False" />
    <asp:Label
        ID="ParamidDocument"
        runat="server"
        Visible="False" />
    <asp:Label
        ID="LabelTypeText"
        runat="server"
        Visible="False" />
    <asp:Panel
        ID="PanelLangueReadOnly"
        runat="server"
        GroupingText="Exemplaires"
        Width="100%">
        <div class="panelcontent">
            <asp:GridView
                ID="GridView2"
                runat="server"
                AllowSorting="True"
                AutoGenerateColumns="False"
                DataSourceID="SqlDataSourceDocument"
                EmptyDataText="(Aucun document associé)"
                Width="100%">
                <Columns>
                    <asp:TemplateField
                        HeaderText="Langue"
                        ShowHeader="False"
                        SortExpression="Langue">
                        <ItemTemplate>
                            <asp:HyperLink
                                ID="HyperLinkURL"
                                runat="server"
                                NavigateUrl='<%# variable("FilePathClt") & Eval("Fichier").toString %>'
                                Text='<%# Eval("Langue") %>'>
                            </asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
        <asp:SqlDataSource
            ID="SqlDataSourceDocumentReadOnly"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:PDP %>"
            SelectCommand="SELECT DocumentLangue.idDocument, DocumentLangue.idLangue, Langue.Langue, Langue.CodeLangue, DocumentLangue.Fichier FROM DocumentLangue INNER JOIN Langue ON DocumentLangue.idLangue = Langue.idLangue WHERE (DocumentLangue.idDocument = @idDocument)">
            <SelectParameters>
                <asp:ControlParameter
                    ControlID="ParamidDocument"
                    Name="idDocument"
                    PropertyName="Text"
                    Type="int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </asp:Panel>
    <asp:Panel
        ID="PanelLangue"
        runat="server"
        GroupingText="Exemplaires"
        Visible="False"
        Width="100%">
        <div class="panelcontent">
            <asp:GridView
                ID="GridView1"
                runat="server"
                AllowSorting="True"
                AutoGenerateColumns="False"
                DataKeyNames="idDocument,idLangue"
                DataSourceID="SqlDataSourceDocument"
                EmptyDataText="(Aucun document associé)"
                Width="100%">
                <Columns>
                    <asp:TemplateField
                        HeaderText="Langue"
                        ShowHeader="False"
                        SortExpression="Langue">
                        <ItemTemplate>
                            <asp:HyperLink
                                ID="HyperLinkURL"
                                runat="server"
                                NavigateUrl='<%# variable("FilePathClt") & Eval("Fichier").toString %>'
                                Text='<%# Eval("Langue") %>'>
                            </asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField
                        ShowHeader="False">
                        <ItemStyle
                            Width="20px" />
                        <ItemTemplate>
                            <asp:ImageButton
                                ID="ImageButton1"
                                runat="server"
                                OnClientClick='<%# DoubleBackslash("ouvrir(""" & variable("FilePathClt") & Eval("Fichier").toString  & """)") %>'
                                SkinID="Edit" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField
                        ShowHeader="False">
                        <ItemStyle
                            Width="20px" />
                        <ItemTemplate>
                            <asp:ImageButton
                                ID="ImageButtonDel"
                                runat="server"
                                CommandName="Delete"
                                OnClientClick='<%# "return confirm(""Etes-vous sur de vouloir supprimer la version en " & Eval("Langue").ToString & " de ce document ?"");" %>'
                                SkinID="Delete" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <br />
            <asp:LinkButton
                ID="LinkButtonAjouter"
                runat="server"
                CssClass="textcenter"
                OnClick="LinkButtonAjouter_Click"
                Text="Ajouter un exemplaire"
                Width="100%">
            </asp:LinkButton>
        </div>
        <asp:SqlDataSource
            ID="SqlDataSourceDocument"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:PDP %>"
            DeleteCommand="DELETE FROM [DocumentLangue] WHERE [idDocument] = @idDocument AND [idLangue] = @idLangue"
            InsertCommand="INSERT INTO DocumentLangue(idLangue, idDocument, Fichier) VALUES (@idLangue, @idDocument, @Fichier)"
            SelectCommand="SELECT DocumentLangue.idDocument, DocumentLangue.idLangue, Langue.Langue, Langue.CodeLangue, DocumentLangue.Fichier FROM DocumentLangue INNER JOIN Langue ON DocumentLangue.idLangue = Langue.idLangue WHERE (DocumentLangue.idDocument = @idDocument)">
            <DeleteParameters>
                <asp:ControlParameter
                    ControlID="ParamidDocument"
                    Name="idDocument"
                    PropertyName="Text"
                    Type="int32" />
                <asp:Parameter
                    Name="idLangue"
                    Type="Int32" />
            </DeleteParameters>
            <SelectParameters>
                <asp:ControlParameter
                    ControlID="ParamidDocument"
                    Name="idDocument"
                    PropertyName="Text"
                    Type="int32" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter
                    Name="idLangue"
                    Type="Int32" />
                <asp:ControlParameter
                    ControlID="ParamidDocument"
                    Name="idDocument"
                    PropertyName="Text"
                    Type="int32" />
                <asp:Parameter
                    Name="Fichier" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource
            ID="SqlDataSourceLangueNew"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:PDP %>"
            SelectCommand="SELECT idLangue, CodeLangue, Langue FROM Langue WHERE (idLangue NOT IN (SELECT idLangue FROM DocumentLangue WHERE (idDocument = @idDocument)))">
            <SelectParameters>
                <asp:ControlParameter
                    ControlID="ParamidDocument"
                    Name="idDocument"
                    PropertyName="Text"
                    Type="int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </asp:Panel>
    <asp:Panel
        ID="PanelNouveau"
        runat="server"
        GroupingText="Nouveau"
        Visible="False"
        Width="100%">
        <div class="panelcontent">
            <table
                width="100%" cellspacing="5">
                <tr>
                    <td style="width: 120px">
                        Langue
                        du<br />
                        nouveau
                        document</td>
                    <td>
                        <asp:DropDownList
                            ID="DropDownListLangueNew"
                            runat="server"
                            DataSourceID="SqlDataSourceLangueNew"
                            DataTextField="Langue"
                            DataValueField="CodeLangue"
                            Width="150px">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="2">
                        Source :
                        <asp:RadioButtonList
                            ID="RadioButtonList1"
                            runat="server"
                            AutoPostBack="True"
                            Width="100%" CellSpacing="10" RepeatDirection="Horizontal">
                            <asp:ListItem
                                Selected="True" Value="Vierge">Modèle</asp:ListItem>
                            <asp:ListItem
                                Value="Copie">Copie</asp:ListItem>
                            <asp:ListItem
                                Value="Fichier"></asp:ListItem>
                            <asp:ListItem
                                Value="Vide">Page blanche</asp:ListItem>
                        </asp:RadioButtonList>
                        </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Panel
                            ID="PanelVierge"
                            runat="server"
                            GroupingText="Documents modèles"
                            Visible="true"
                            Width="100%">
                            <div class="panelcontent">
                                <asp:GridView
                                    ID="GridViewDocVierge"
                                    runat="server"
                                    AllowSorting="True"
                                    AutoGenerateColumns="False"
                                    DataKeyNames="Fichier"
                                    DataSourceID="SqlDataSourceDocVierge"
                                    EmptyDataText="(Aucun document trouvé)"
                                    OnSelectedIndexChanged="GridViewDoc_SelectedIndexChanged"
                                    Width="100%">
                                    <Columns>
                                        <asp:BoundField
                                            DataField="Langue"
                                            HeaderText="Langue"
                                            SortExpression="Langue" />
                                        <asp:CommandField
                                            ButtonType="Button"
                                            ShowSelectButton="True"
                                            SelectText="Copier">
                                            <ItemStyle
                                                Width="50px" />
                                        </asp:CommandField>
                                    </Columns>
                                </asp:GridView>
                                <asp:SqlDataSource
                                    ID="SqlDataSourceDocVierge"
                                    runat="server"
                                    ConnectionString="<%$ ConnectionStrings:PDP %>"
                                    SelectCommand="SELECT Document.idDocument, DocumentLangue.Fichier, Langue.idLangue, Langue.CodeLangue, Langue.Langue FROM Document INNER JOIN DocumentLangue ON Document.idDocument = DocumentLangue.idDocument INNER JOIN Langue ON DocumentLangue.idLangue = Langue.idLangue WHERE (Document.Type LIKE '%' + 'ADMIN\' + @Type + '%')">
                                    <SelectParameters>
                                        <asp:ControlParameter
                                            ControlID="LabelType"
                                            Name="Type"
                                            PropertyName="Text"
                                            Type="string" />
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </div>
                        </asp:Panel>
                        <asp:Panel
                            ID="PanelCopie"
                            runat="server"
                            GroupingText="Copier à partir de"
                            Visible="False"
                            Width="100%">
                            <div class="panelcontent">
                                <asp:Panel
                                    ID="Panel3"
                                    runat="server"
                                    GroupingText="Rechercher"
                                    Width="100%">
                                    <table style="width: 100%">
                                        <tr>
                                            <td>
                                                Entreprise</td>
                                            <td>
                                                <asp:DropDownList
                                                    ID="DropDownListEntreprise"
                                                    runat="server"
                                                    AppendDataBoundItems="True"
                                                    AutoPostBack="True"
                                                    DataSourceID="SqlDataSourceEntreprise"
                                                    DataTextField="Nom"
                                                    DataValueField="idEntreprise"
                                                    OnDataBinding="DropDownListClear_DataBinding"
                                                    Width="200px">
                                                </asp:DropDownList>
                                                <asp:SqlDataSource
                                                    ID="SqlDataSourceEntreprise"
                                                    runat="server"
                                                    ConnectionString="<%$ ConnectionStrings:PDP %>"
                                                    SelectCommand="SELECT [idEntreprise], [Nom] FROM [Entreprise] ORDER BY [Nom]">
                                                </asp:SqlDataSource>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Numéro PDP</td>
                                            <td>
                                                <asp:TextBox
                                                    ID="TextBoxNumeroPDP"
                                                    runat="server"
                                                    AutoPostBack="True"
                                                    Width="100px" /></td>
                                        </tr>
                                        <tr>
                                            <td style="height: 21px">
                                                Commanditaire</td>
                                            <td style="height: 21px">
                                                <asp:DropDownList
                                                    ID="DropDownListCommanditaire"
                                                    runat="server"
                                                    AppendDataBoundItems="True"
                                                    AutoPostBack="True"
                                                    DataSourceID="SqlDataSourceDonneurOrdre"
                                                    DataTextField="NomPrenom"
                                                    DataValueField="idDonneurOrdre"
                                                    OnDataBinding="DropDownListClear_DataBinding">
                                                </asp:DropDownList>
                                                <asp:SqlDataSource
                                                    ID="SqlDataSourceDonneurOrdre"
                                                    runat="server"
                                                    ConnectionString="<%$ ConnectionStrings:PDP %>"
                                                    SelectCommand="SELECT idDonneurOrdre, Nom + ISNULL(' ' + Prenom, '') AS NomPrenom FROM DonneurOrdre">
                                                </asp:SqlDataSource>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Langue</td>
                                            <td>
                                                <asp:DropDownList
                                                    ID="DropDownListLangue"
                                                    runat="server"
                                                    AppendDataBoundItems="True"
                                                    AutoPostBack="True"
                                                    DataSourceID="SqlDataSourceLangue"
                                                    DataTextField="Langue"
                                                    DataValueField="idLangue"
                                                    OnDataBinding="DropDownListClear_DataBinding">
                                                </asp:DropDownList>
                                                <asp:SqlDataSource
                                                    ID="SqlDataSourceLangue"
                                                    runat="server"
                                                    ConnectionString="<%$ ConnectionStrings:PDP %>"
                                                    SelectCommand="SELECT [idLangue], [Langue], [CodeLangue] FROM [Langue]">
                                                </asp:SqlDataSource>
                                            </td>
                                        </tr>
                                    </table>
                                </asp:Panel>
                                <br />
                                <asp:GridView
                                    ID="GridViewDoc"
                                    runat="server"
                                    AutoGenerateColumns="False"
                                    DataKeyNames="Fichier"
                                    DataSourceID="SqlDataSourceDoc"
                                    EmptyDataText="(Aucun document trouvé)"
                                    OnSelectedIndexChanged="GridViewDoc_SelectedIndexChanged"
                                    Width="100%">
                                    <Columns>
                                        <asp:TemplateField
                                            HeaderText="Nom"
                                            SortExpression="Nom">
                                            <ItemTemplate>
                                                <asp:HyperLink
                                                    ID="HyperLink1"
                                                    runat="server"
                                                    NavigateUrl='<%# variable("FilePathClt") & Eval("Fichier").toString %>'>
                                                    <asp:Label
                                                        ID="Label1"
                                                        runat="server"
                                                        Text='<%# Bind("Nom") %>' />
                                                </asp:HyperLink>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField
                                            DataField="Langue"
                                            HeaderText="Langue"
                                            SortExpression="Langue" />
                                        <asp:CommandField
                                            ButtonType="Button"
                                            SelectText="Copier"
                                            ShowSelectButton="True">
                                            <ItemStyle
                                                Width="50px" />
                                        </asp:CommandField>
                                    </Columns>
                                </asp:GridView>
                                <br />
                            </div>
                        </asp:Panel>
                        <asp:Panel
                            ID="PanelVide"
                            runat="server"
                            Width="100%">
                            <br />
                            <table width="100%">
                                <tr>
                                    <td style="text-align: center">
                                        <asp:LinkButton
                                            ID="LinkButtonAjouterVide"
                                            runat="server">Créer un document vide</asp:LinkButton></td>
                                </tr>
                            </table>
                            <br />
                        </asp:Panel>
                        <asp:Panel
                            ID="PanelUpload"
                            runat="server"
                            Width="100%">
                            <table width="100%">
                                <tr>
                                    <td style="text-align: right">
                                        Fichier :
                                    </td>
                                    <td style="width: 80%">
                                        <asp:FileUpload
                                            ID="FileUpload1"
                                            runat="server"
                                            Width="100%" /></td>
                                    <td>
                                        <asp:Button
                                            ID="ButtonAjouterFile"
                                            runat="server"
                                            Height="1.5em"
                                            Text="Ajouter"
                                            Width="7em" /></td>
                                </tr>
                            </table>
                        </asp:Panel>
                    </td>
                </tr>
                <tr>
                    <td align="center"
                        colspan="2">
                        <br />
                        <asp:LinkButton
                            ID="LinkButtonAnnuler"
                            runat="server">Annuler</asp:LinkButton>
                    </td>
                </tr>
            </table>
        </div>
    </asp:Panel>
    <asp:SqlDataSource
        ID="SqlDataSourceDoc"
        runat="server"
        ConnectionString="<%$ ConnectionStrings:PDP %>"
        SelectCommand="SELECT Document.idDocument, Document.Type, CONVERT (varchar, CGS.DateCreation, 103) AS Nom, DocumentLangue.Fichier, Langue.Langue, DocumentLangue.idLangue FROM Document INNER JOIN DocumentLangue ON Document.idDocument = DocumentLangue.idDocument INNER JOIN Langue ON DocumentLangue.idLangue = Langue.idLangue INNER JOIN CGS ON Document.idDocument = CGS.idDocument WHERE (Document.Type LIKE '%' + @Type + '%') UNION SELECT Document_2.idDocument, Document_2.Type, Avenant.Nom AS nom, DocumentLangue_2.Fichier, Langue_2.Langue, DocumentLangue_2.idLangue FROM DocumentLangue AS DocumentLangue_2 INNER JOIN Document AS Document_2 INNER JOIN Avenant ON Document_2.idDocument = Avenant.idDocument ON DocumentLangue_2.idDocument = Document_2.idDocument INNER JOIN Langue AS Langue_2 ON DocumentLangue_2.idLangue = Langue_2.idLangue LEFT OUTER JOIN AvenantPDP LEFT OUTER JOIN Entreprise INNER JOIN PDP ON Entreprise.idEntreprise = PDP.idEntreprise INNER JOIN DonneurOrdreCommande INNER JOIN DonneurOrdre ON DonneurOrdreCommande.idDonneurOrdre = DonneurOrdre.idDonneurOrdre INNER JOIN Commande ON DonneurOrdreCommande.idCommande = Commande.idCommande ON PDP.idPDP = Commande.idPDP ON AvenantPDP.idPDP = PDP.idPDP ON Avenant.idAvenant = AvenantPDP.idAvenant WHERE (ISNULL(CAST(PDP.idEntreprise AS varchar), '') LIKE '%' + @idEntreprise + '%') AND (ISNULL(CAST(PDP.Numero AS varchar), '') LIKE '%' + @NumeroPDP + '%') AND (ISNULL(CAST(DocumentLangue_2.idLangue AS varchar), '') LIKE '%' + @idLangue + '%') AND (ISNULL(DonneurOrdre.Nom, '') LIKE '%' + @DonneurOrdre + '%') AND (Document_2.Type LIKE '%' + @Type + '%') UNION SELECT Document_1.idDocument, Document_1.Type, PDP_1.Intitule AS nom, DocumentLangue_1.Fichier, Langue_1.Langue, DocumentLangue_1.idLangue FROM Entreprise AS Entreprise_1 INNER JOIN Document AS Document_1 INNER JOIN DocumentLangue AS DocumentLangue_1 ON Document_1.idDocument = DocumentLangue_1.idDocument INNER JOIN Langue AS Langue_1 ON DocumentLangue_1.idLangue = Langue_1.idLangue INNER JOIN PDP AS PDP_1 ON Document_1.idDocument = PDP_1.idDocument ON Entreprise_1.idEntreprise = PDP_1.idEntreprise LEFT OUTER JOIN DonneurOrdre AS DonneurOrdre_1 INNER JOIN DonneurOrdreCommande AS DonneurOrdreCommande_1 ON DonneurOrdre_1.idDonneurOrdre = DonneurOrdreCommande_1.idDonneurOrdre INNER JOIN Commande AS Commande_1 ON DonneurOrdreCommande_1.idCommande = Commande_1.idCommande ON PDP_1.idPDP = Commande_1.idPDP WHERE (ISNULL(CAST(PDP_1.idEntreprise AS varchar), '') LIKE '%' + @idEntreprise + '%') AND (ISNULL(CAST(PDP_1.Numero AS varchar), '') LIKE '%' + @NumeroPDP + '%') AND (ISNULL(CAST(DocumentLangue_1.idLangue AS varchar), '') LIKE '%' + @idLangue + '%') AND (ISNULL(DonneurOrdre_1.Nom, '') LIKE '%' + @DonneurOrdre + '%') AND (Document_1.Type LIKE '%' + @Type + '%')">
        <SelectParameters>
            <asp:ControlParameter
                ControlID="LabelType"
                Name="Type"
                PropertyName="Text"
                Type="string" />
            <asp:ControlParameter
                ControlID="DropDownListEntreprise"
                DefaultValue="%"
                Name="idEntreprise"
                PropertyName="SelectedValue"
                Type="String" />
            <asp:ControlParameter
                ControlID="TextBoxNumeroPDP"
                DefaultValue="%"
                Name="NumeroPDP"
                PropertyName="Text"
                Type="String" />
            <asp:ControlParameter
                ControlID="DropDownListLangue"
                DefaultValue="%"
                Name="idLangue"
                PropertyName="SelectedValue" />
            <asp:ControlParameter
                ControlID="DropDownListCommanditaire"
                DefaultValue="%"
                Name="DonneurOrdre"
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>
    voici le code vb de mon module :
    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
     
    Partial Class Modules_Document
        Inherits System.Web.UI.UserControl
     
     
        Public Function InitMode(ByVal Mode As FormViewMode, ByVal idDocument As String) As Boolean
            ViewState.Clear()
     
            InitMode = IsNumeric(idDocument) 'S'il y'a un document
     
            If InitMode Then
                ParamidDocument.Text = idDocument
                'On récupère son type (AVE, PDP, CGS)
                LabelPrefixe.Text = ExecuteSQL("Select Type From Document Where idDocument = " & ParamidDocument.Text.ToString).ToString
     
                Select Case LabelPrefixe.Text
                    Case "AVE"
                        LabelTypeText.Text = "de l'avenant"
                    Case "PDP"
                        LabelTypeText.Text = "du plan de prévention"
                    Case "CGS"
                        LabelTypeText.Text = "des consignes générales de sécurité"
                    Case "ADMIN\AVE"
                        LabelTypeText.Text = "modèle(s) de l'avenant"
                    Case "ADMIN\PDP"
                        LabelTypeText.Text = "modèle(s) du plan de prévention"
                    Case "ADMIN\CGS"
                        LabelTypeText.Text = "modèle(s) des consignes générales de sécurité"
                End Select
     
                LabelType.Text = LabelPrefixe.Text.Replace("ADMIN\", "")
     
                PanelLangueReadOnly.GroupingText = "Exemplaire(s) " & LabelTypeText.Text
                PanelLangue.GroupingText = "Exemplaire(s) " & LabelTypeText.Text
                LinkButtonAjouter.Text = "Ajouter un exemplaire " & LabelTypeText.Text
     
                'On affiche les bons panels suivant le mode de visualisation
                PanelLangueReadOnly.Visible = (Mode = FormViewMode.ReadOnly)
                PanelLangue.Visible = (Mode <> FormViewMode.ReadOnly)
            End If
     
        End Function
     
        Public Function SaveAndGetID() As Integer
            Try
                SaveAndGetID = CInt(ParamidDocument.Text)
            Catch ex As Exception
                SaveAndGetID = -1
            End Try
        End Function
     
        Public Shared Sub DeleteID(ByVal idDocument As String)
            If IsNumeric(idDocument) Then
                Dim idDocLng As Object
                idDocLng = ExecuteSQL("Select idLangue From DocumentLangue Where idDocument = " & idDocument)
                While IsNumeric(idDocLng)
                    DeleteLangueID(idDocument, idDocLng.ToString)
                    idDocLng = ExecuteSQL("Select idLangue From DocumentLangue Where idDocument = " & idDocument)
                End While
                ExecuteSQL("Delete From Document Where idDocument = " & idDocument)
            End If
        End Sub
     
        Public Shared Sub DeleteLangueID(ByVal idDocument As String, ByVal idLangue As String)
            If IsNumeric(idDocument) And IsNumeric(idLangue) Then
                Dim File As Object
                File = ExecuteSQL("Select Fichier From DocumentLangue Where idDocument = " & idDocument & " and idLangue = " & idLangue).ToString()
                If Not IsNothing(File) And File.ToString.Trim <> "" Then
                    If System.IO.File.Exists(Variable("FilePathSrv") & File) Then
                        System.IO.File.Delete(Variable("FilePathSrv") & File)
                    End If
                    ExecuteSQL("Delete From DocumentLangue Where idDocument = " & idDocument & " and idLangue = " & idLangue)
                End If
            End If
        End Sub
     
     
        'Bouton Ajouter un élément
        Protected Sub LinkButtonAjouter_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            PanelNouveau.Visible = True
            PanelLangue.Visible = False
            GridViewDoc.DataBind()
            GridViewDocVierge.DataBind()
            DropDownListLangueNew.DataBind()
            RadioButtonList1_SelectedIndexChanged(RadioButtonList1, Nothing)
        End Sub
     
        ' Affiche le bouton "ajouter" s'il existe une langue
        ' pour laquel il n'y a pas d'exemplaire du document
        Protected Sub SqlDataSourceLangueNew_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSourceLangueNew.Selected
            LinkButtonAjouter.Visible = (e.AffectedRows <> 0)
        End Sub
     
        'Bouton Annuler
        Protected Sub LinkButtonAnnuler_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonAnnuler.Click
            PanelNouveau.Visible = False
            PanelLangue.Visible = True
        End Sub
     
        'Procédure de création d'un nouveau document
        Protected Sub SaveDocument(ByVal Fichier As String)
            'Enregistrement dans la base de données
            With CType(FindControl("SqlDataSourceDocument"), SqlDataSource)
                With .InsertParameters
                    .Clear()
                    .Add("idDocument", ParamidDocument.Text.ToString)
                    .Add("Fichier", Fichier)
                    .Add("idLangue", ExecuteSQL("Select idLangue From Langue where CodeLangue = '" & DropDownListLangueNew.SelectedValue & "'").ToString)
                End With
                .Insert()
            End With
     
        End Sub
     
        Function FindNewDocumentLocation(ByVal Extension As String) As String
            'Création du nom du nouveau fichier
            FindNewDocumentLocation = LabelPrefixe.Text.ToString + "-"
            If Not LabelPrefixe.Text Like "*ADMIN\*" Then
                FindNewDocumentLocation = FindNewDocumentLocation + ParamidDocument.Text.ToString + "-"
            End If
            FindNewDocumentLocation = FindNewDocumentLocation + DropDownListLangueNew.SelectedValue
            FindNewDocumentLocation = FindNewDocumentLocation + Extension
        End Function
     
        ' Affichage suivant le choix de la source de copie
        Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
            Select Case RadioButtonList1.SelectedValue
                Case "Copie"
                    PanelCopie.Visible = True
                    PanelVierge.Visible = False
                    PanelVide.Visible = False
                    PanelUpload.Visible = False
                Case "Vierge"
                    PanelVierge.Visible = True
                    PanelCopie.Visible = False
                    PanelVide.Visible = False
                    PanelUpload.Visible = False
                Case "Vide"
                    PanelVierge.Visible = False
                    PanelCopie.Visible = False
                    PanelVide.Visible = True
                    PanelUpload.Visible = False
                Case "Fichier"
                    PanelVierge.Visible = False
                    PanelCopie.Visible = False
                    PanelVide.Visible = False
                    PanelUpload.Visible = True
            End Select
        End Sub
     
     
        'Selection du document à copier
        Protected Sub GridViewDoc_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim GV As GridView = CType(sender, GridView)
            Dim FichierSource As String
            Dim FichierDestination As String
     
            FichierSource = GV.DataKeys(GV.SelectedRow.RowIndex)("Fichier").ToString
            FichierDestination = FindNewDocumentLocation(FichierSource.Substring(FichierSource.LastIndexOf(".")))
     
            'Création du nouveau document
     
            System.IO.File.Copy(Variable("FilePathSrv") & FichierSource, _
                    Variable("FilePathSrv") & FichierDestination, True)
     
     
            SaveDocument(FichierDestination)
     
            GV.SelectedIndex = -1 'Déselection
            'Actualisation et retour à l'affichage normal
            DropDownListLangueNew.DataBind()
            PanelNouveau.Visible = False
            PanelLangue.Visible = True
        End Sub
     
        Protected Sub LinkButtonAjouterVide_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonAjouterVide.Click
            Dim FichierDestination As String
     
            With Variable("EmptyFile")
                FichierDestination = FindNewDocumentLocation(.Substring(.LastIndexOf(".")))
            End With
     
            If System.IO.File.Exists(Variable("FilePathSrv") & Variable("EmptyFile")) Then
                System.IO.File.Copy(Variable("FilePathSrv") & Variable("EmptyFile"), _
                    Variable("FilePathSrv") & FichierDestination, True)
     
            SaveDocument(FichierDestination)
            DropDownListLangueNew.DataBind()
            PanelNouveau.Visible = False
            PanelLangue.Visible = True
            End If
     
        End Sub
     
        'Initialisation des DropDownList de recherche
        Protected Sub DropDownListClear_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim DDL As DropDownList = CType(sender, DropDownList)
            'On efface tout
            DDL.ClearSelection()
            DDL.Items.Clear()
            'Ajout de l'élément vide
            DDL.Items.Add("")
        End Sub
     
        Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
            e.Cancel = True
            DeleteLangueID(e.Keys("idDocument"), e.Keys("idLangue"))
            GridView1.DataBind()
        End Sub
     
        Protected Sub ButtonAjouterFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAjouterFile.Click
            If FileUpload1.HasFile Then
                Dim FichierDestination As String
                Dim Extension As String
                Extension = FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("."))
                FichierDestination = FindNewDocumentLocation(Extension)
                FileUpload1.SaveAs(Variable("FilePathSrv") & FichierDestination)
                SaveDocument(FichierDestination)
                DropDownListLangueNew.DataBind()
                PanelNouveau.Visible = False
                PanelLangue.Visible = True
            End If
        End Sub
     
    End Class
    merci pour votre aide
    cordialement.

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 42
    Par défaut
    Citation Envoyé par Geo2A Voir le message
    Bonjour,

    Pour ma part j'utilise la chose suivante:

    J'ai créé un modèle de document sous Word (*.dotx), dans le quel j'ai créé des BookMark aux endroits où je veux insérer des données via VB.

    Dans mon projet VB.NET j'ai ajouté les références :
    Microsoft.office.Core
    Microsoft.Office.Interop.Word
    Microsoft.Office.Tools.Word.v9.0

    Dans le code ça donne ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Dim AppWord As New Microsoft.Office.Interop.Word.Application
                    Dim w As Microsoft.Office.Interop.Word.Document = AppWord.Documents.Add("P:\Dossiers\ModeleAR2.dotx")
                    w.Bookmarks("Titre").Range.Text = titre
                    w.Bookmarks("Prenom").Range.Text = Prenom
                    w.Bookmarks("Nom").Range.Text = Nom
                    w.Bookmarks("AdresseLigne1").Range.Text = AdresseLigne1
                    w.Bookmarks("Codepostal").Range.Text = Codepostal
                    w.Bookmarks("Ville").Range.Text = Ville
                    w.Bookmarks("Datecourrier").Range.Text =Format(datereception, "dd/mm/yyyy")
     
     
                    Dim cl = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges
                    w.SaveAs("P:\Courrierjuridique\" & DMEC.Nom & "\AR_" & DMEC.Nom & ".docx")

    A+
    Bonjour,

    Je n'arrive pas à trouver la référence : Microsoft.Office.Tools.Word.v9.0

    J'ai 2 erreurs à la compil j'imagine que ça vient de ça.

    Impossible d'incorporer les types interop à partir de l'assembly 'Interop.VSTOEE100', car l'attribut 'Guid' est manquant.

    Impossible d'incorporer les types interop à partir de l'assembly 'Interop.VSTOEE100', car l'attribut 'ImportedFromTypeLib' ou 'PrimaryInteropAssembly' est manquant
    Merci d'avance pour votre aide.

    Romain

Discussions similaires

  1. [WD-2003] Remplissage automatique de documents word
    Par Caltys dans le forum Word
    Réponses: 4
    Dernier message: 20/12/2011, 02h27
  2. [WD-2010] Pré remplissage d'un document Word
    Par Serigne-BA dans le forum VBA Word
    Réponses: 2
    Dernier message: 10/10/2011, 11h43
  3. remplissage d'un document word à partir de vb6
    Par azzouz_soui dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 21/05/2008, 15h58
  4. [VB6] Erreur lors de l'ouverture d'un document Word
    Par Marco le Pouillot dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 03/01/2003, 09h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo