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

C# Discussion :

XmlNode vs Paragraph


Sujet :

C#

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 63
    Points : 38
    Points
    38
    Par défaut XmlNode vs Paragraph
    Bonjour,
    J'ai une application qui modifie un fichier docx et pour modifier le text je touche au code xml
    Mon problème est que j'ai une fonction me renvoyant un object Paragraphque je doit insérer dans un XmlDocument, Le problème c'est que la fonction InsertAfter/Before ne fonctionne pas.
    Est ce que quelqu'un à une idée pour la résolution du problème?
    Merci.

  2. #2
    Membre habitué Avatar de bibbi
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    113
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 113
    Points : 137
    Points
    137
    Par défaut
    Salut.

    Je pense qu'il va falloir un peu plus de détails pour avoir de l'aide.

    Donne le code qui ne fonctionne pas et surtout explique pourquoi çà ne fonctionne pas:

    - Çà ne compile pas?
    - Çà compile mais lève une exception durant l'exécution?
    - Çà compile et aucune exception n'est levée mais le résultat attendu n'est pas le bon?

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 63
    Points : 38
    Points
    38
    Par défaut
    Je ne compile pas encore.
    Lorsque je tape VS me souligne toute la fonction insert et me dit que ma fonction qui renvoie l'object Paragraph ne correspont pas a un XmlNode ou un XmlDocument

  4. #4
    Membre éprouvé
    Avatar de Gurdil le nain
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 468
    Points : 1 111
    Points
    1 111
    Par défaut
    Montre nous ton code d'insert stp.

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 63
    Points : 38
    Points
    38
    Par défaut
    méthode qui génére le xmlnode
    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
     
    public Paragraph GenerateParagraph()
            {
                Paragraph paragraph1 = new Paragraph(){ RsidParagraphAddition = "00C17B72", RsidParagraphProperties = "00C17B72", RsidRunAdditionDefault = "00C17B72" };
     
                ParagraphProperties paragraphProperties1 = new ParagraphProperties();
     
                Tabs tabs1 = new Tabs();
                TabStop tabStop1 = new TabStop(){ Val = TabStopValues.Center, Position = 1418 };
                TabStop tabStop2 = new TabStop(){ Val = TabStopValues.Center, Position = 2552 };
                TabStop tabStop3 = new TabStop(){ Val = TabStopValues.Center, Position = 4111 };
                TabStop tabStop4 = new TabStop(){ Val = TabStopValues.Right, Position = 6237 };
                TabStop tabStop5 = new TabStop(){ Val = TabStopValues.Right, Position = 7371 };
                TabStop tabStop6 = new TabStop(){ Val = TabStopValues.Right, Position = 8505 };
     
                tabs1.Append(tabStop1);
                tabs1.Append(tabStop2);
                tabs1.Append(tabStop3);
                tabs1.Append(tabStop4);
                tabs1.Append(tabStop5);
                tabs1.Append(tabStop6);
                SuppressAutoHyphens suppressAutoHyphens1 = new SuppressAutoHyphens();
                AutoSpaceDE autoSpaceDE1 = new AutoSpaceDE();
                SpacingBetweenLines spacingBetweenLines1 = new SpacingBetweenLines(){ Before = "200", After = "200", Line = "240", LineRule = LineSpacingRuleValues.Auto };
     
                ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
                RunFonts runFonts1 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                Kern kern1 = new Kern(){ Val = (UInt32Value)0U };
                FontSize fontSize1 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript(){ Val = "16" };
     
                paragraphMarkRunProperties1.Append(runFonts1);
                paragraphMarkRunProperties1.Append(kern1);
                paragraphMarkRunProperties1.Append(fontSize1);
                paragraphMarkRunProperties1.Append(fontSizeComplexScript1);
     
                paragraphProperties1.Append(tabs1);
                paragraphProperties1.Append(suppressAutoHyphens1);
                paragraphProperties1.Append(autoSpaceDE1);
                paragraphProperties1.Append(spacingBetweenLines1);
                paragraphProperties1.Append(paragraphMarkRunProperties1);
     
                Run run1 = new Run();
     
                RunProperties runProperties1 = new RunProperties();
                RunFonts runFonts2 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize2 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript(){ Val = "16" };
                Underline underline1 = new Underline(){ Val = UnderlineValues.Single };
     
                runProperties1.Append(runFonts2);
                runProperties1.Append(fontSize2);
                runProperties1.Append(fontSizeComplexScript2);
                runProperties1.Append(underline1);
                Text text1 = new Text();
                text1.Text = "N° Facture";
     
                run1.Append(runProperties1);
                run1.Append(text1);
     
                Run run2 = new Run();
     
                RunProperties runProperties2 = new RunProperties();
                RunFonts runFonts3 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize3 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript3 = new FontSizeComplexScript(){ Val = "16" };
     
                runProperties2.Append(runFonts3);
                runProperties2.Append(fontSize3);
                runProperties2.Append(fontSizeComplexScript3);
                TabChar tabChar1 = new TabChar();
     
                run2.Append(runProperties2);
                run2.Append(tabChar1);
     
                Run run3 = new Run();
     
                RunProperties runProperties3 = new RunProperties();
                RunFonts runFonts4 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize4 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript4 = new FontSizeComplexScript(){ Val = "16" };
                Underline underline2 = new Underline(){ Val = UnderlineValues.Single };
     
                runProperties3.Append(runFonts4);
                runProperties3.Append(fontSize4);
                runProperties3.Append(fontSizeComplexScript4);
                runProperties3.Append(underline2);
                Text text2 = new Text();
                text2.Text = "Date";
     
                run3.Append(runProperties3);
                run3.Append(text2);
     
                Run run4 = new Run();
     
                RunProperties runProperties4 = new RunProperties();
                RunFonts runFonts5 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize5 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript5 = new FontSizeComplexScript(){ Val = "16" };
     
                runProperties4.Append(runFonts5);
                runProperties4.Append(fontSize5);
                runProperties4.Append(fontSizeComplexScript5);
                TabChar tabChar2 = new TabChar();
     
                run4.Append(runProperties4);
                run4.Append(tabChar2);
     
                Run run5 = new Run();
     
                RunProperties runProperties5 = new RunProperties();
                RunFonts runFonts6 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize6 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript6 = new FontSizeComplexScript(){ Val = "16" };
                Underline underline3 = new Underline(){ Val = UnderlineValues.Single };
     
                runProperties5.Append(runFonts6);
                runProperties5.Append(fontSize6);
                runProperties5.Append(fontSizeComplexScript6);
                runProperties5.Append(underline3);
                Text text3 = new Text();
                text3.Text = "Echue le";
     
                run5.Append(runProperties5);
                run5.Append(text3);
     
                Run run6 = new Run();
     
                RunProperties runProperties6 = new RunProperties();
                RunFonts runFonts7 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize7 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript7 = new FontSizeComplexScript(){ Val = "16" };
     
                runProperties6.Append(runFonts7);
                runProperties6.Append(fontSize7);
                runProperties6.Append(fontSizeComplexScript7);
                TabChar tabChar3 = new TabChar();
     
                run6.Append(runProperties6);
                run6.Append(tabChar3);
     
                Run run7 = new Run();
     
                RunProperties runProperties7 = new RunProperties();
                RunFonts runFonts8 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize8 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript8 = new FontSizeComplexScript(){ Val = "16" };
                Underline underline4 = new Underline(){ Val = UnderlineValues.Single };
     
                runProperties7.Append(runFonts8);
                runProperties7.Append(fontSize8);
                runProperties7.Append(fontSizeComplexScript8);
                runProperties7.Append(underline4);
                Text text4 = new Text();
                text4.Text = "Mode de Règlement";
     
                run7.Append(runProperties7);
                run7.Append(text4);
     
                Run run8 = new Run();
     
                RunProperties runProperties8 = new RunProperties();
                RunFonts runFonts9 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize9 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript9 = new FontSizeComplexScript(){ Val = "16" };
     
                runProperties8.Append(runFonts9);
                runProperties8.Append(fontSize9);
                runProperties8.Append(fontSizeComplexScript9);
                TabChar tabChar4 = new TabChar();
     
                run8.Append(runProperties8);
                run8.Append(tabChar4);
     
                Run run9 = new Run();
     
                RunProperties runProperties9 = new RunProperties();
                RunFonts runFonts10 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize10 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript10 = new FontSizeComplexScript(){ Val = "16" };
                Underline underline5 = new Underline(){ Val = UnderlineValues.Single };
     
                runProperties9.Append(runFonts10);
                runProperties9.Append(fontSize10);
                runProperties9.Append(fontSizeComplexScript10);
                runProperties9.Append(underline5);
                Text text5 = new Text();
                text5.Text = "Versé";
     
                run9.Append(runProperties9);
                run9.Append(text5);
     
                Run run10 = new Run();
     
                RunProperties runProperties10 = new RunProperties();
                RunFonts runFonts11 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize11 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript11 = new FontSizeComplexScript(){ Val = "16" };
     
                runProperties10.Append(runFonts11);
                runProperties10.Append(fontSize11);
                runProperties10.Append(fontSizeComplexScript11);
                TabChar tabChar5 = new TabChar();
     
                run10.Append(runProperties10);
                run10.Append(tabChar5);
     
                Run run11 = new Run();
     
                RunProperties runProperties11 = new RunProperties();
                RunFonts runFonts12 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize12 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript12 = new FontSizeComplexScript(){ Val = "16" };
                Underline underline6 = new Underline(){ Val = UnderlineValues.Single };
     
                runProperties11.Append(runFonts12);
                runProperties11.Append(fontSize12);
                runProperties11.Append(fontSizeComplexScript12);
                runProperties11.Append(underline6);
                Text text6 = new Text();
                text6.Text = "Total TTC";
     
                run11.Append(runProperties11);
                run11.Append(text6);
     
                Run run12 = new Run();
     
                RunProperties runProperties12 = new RunProperties();
                RunFonts runFonts13 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize13 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript13 = new FontSizeComplexScript(){ Val = "16" };
     
                runProperties12.Append(runFonts13);
                runProperties12.Append(fontSize13);
                runProperties12.Append(fontSizeComplexScript13);
                TabChar tabChar6 = new TabChar();
     
                run12.Append(runProperties12);
                run12.Append(tabChar6);
     
                Run run13 = new Run();
     
                RunProperties runProperties13 = new RunProperties();
                RunFonts runFonts14 = new RunFonts(){ Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial" };
                FontSize fontSize14 = new FontSize(){ Val = "16" };
                FontSizeComplexScript fontSizeComplexScript14 = new FontSizeComplexScript(){ Val = "16" };
                Underline underline7 = new Underline(){ Val = UnderlineValues.Single };
     
                runProperties13.Append(runFonts14);
                runProperties13.Append(fontSize14);
                runProperties13.Append(fontSizeComplexScript14);
                runProperties13.Append(underline7);
                Text text7 = new Text();
                text7.Text = "Solde Dû";
     
                run13.Append(runProperties13);
                run13.Append(text7);
     
                paragraph1.Append(paragraphProperties1);
                paragraph1.Append(run1);
                paragraph1.Append(run2);
                paragraph1.Append(run3);
                paragraph1.Append(run4);
                paragraph1.Append(run5);
                paragraph1.Append(run6);
                paragraph1.Append(run7);
                paragraph1.Append(run8);
                paragraph1.Append(run9);
                paragraph1.Append(run10);
                paragraph1.Append(run11);
                paragraph1.Append(run12);
                paragraph1.Append(run13);
                return paragraph1;
            }
    Et voici la boucle d'insertion

    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
     
    foreach (Relance r in list.Relances)
                {
                    Paragraph xml = initXmlRelance();
                    XmlNode cible = doc.DocumentElement.FirstChild.ChildNodes[14];
     
                    try
                    {
                        doc.InsertBefore(xml, cible);
                    }
                    catch (ArgumentException e)
                    {
                        MessageBox.Show(e.Message);
                        MessageBox.Show(e.Source);
                        MessageBox.Show(e.TargetSite.ToString());
                    }
                }
     
                return doc;

  6. #6
    Membre éprouvé
    Avatar de Gurdil le nain
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 468
    Points : 1 111
    Points
    1 111
    Par défaut
    Ouais ba en effet, comme te dis le compilateur...tu essayes de foutre un Paragraphe là où il attend un XmlNode...qui ne sont pas de même types.

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 63
    Points : 38
    Points
    38
    Par défaut
    C'est exactement le problème, Il faudrait en fait mettre le paragraph dans le xmlNode et sa devrait aller, mais je sais pas comment le mettre

  8. #8
    Membre éprouvé
    Avatar de Gurdil le nain
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 468
    Points : 1 111
    Points
    1 111
    Par défaut
    Tu pourrais l'ajouter au texte du nœud, mais je ne sais pas si ça marchera (niveau mise en page).

    Mais je pige pas bien la finalité du truc ^^

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 63
    Points : 38
    Points
    38
    Par défaut
    Modification d'un docx qui n'est pas un template, et ceci reproduira une espèce de tableau

  10. #10
    Membre éprouvé
    Avatar de Gurdil le nain
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 468
    Points : 1 111
    Points
    1 111
    Par défaut
    Ouais ça j'avais pigé Mais en gros, tu veux juste ajouter un paragraphe à un docx, pourquoi passer par du XML ?

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 63
    Points : 38
    Points
    38
    Par défaut
    Pour garder la mise en page du tableau

  12. #12
    Membre éprouvé
    Avatar de Gurdil le nain
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 468
    Points : 1 111
    Points
    1 111
    Par défaut
    Fais voir ton xml stp.

Discussions similaires

  1. Aligner à gauche et à droite dans un paragraphe
    Par camboui dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 02/11/2005, 10h36
  2. [CSS] Retrait de paragraphe
    Par Phenomenium dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 22/10/2005, 11h09
  3. [XSLT] Encadrer des paragraphes ayant les mêmes balises
    Par billou13 dans le forum XSL/XSLT/XPATH
    Réponses: 6
    Dernier message: 21/10/2005, 10h18
  4. Garder les style de paragraphe dans un formulaire
    Par Death83 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 10/08/2005, 14h04
  5. Espace entre paragraphes
    Par Laskar dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 03/04/2005, 14h16

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