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 :

automation word numérotation


Sujet :

C#

  1. #1
    Membre confirmé
    Profil pro
    Administrateur réseau
    Inscrit en
    Mai 2009
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Administrateur réseau

    Informations forums :
    Inscription : Mai 2009
    Messages : 58
    Par défaut automation word numérotation
    Bonjour,

    mon application en c# génère un document word, dans celui-ci je souhaite intégrer une numérotation pour bien distinguer les modalités du documents.

    j'ai généré une macro sur word pour m'inspirer du code VBA produit mais je n'arrive pas à le retranscrire en c#

    Voici le 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
    With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
            .NumberFormat = "%1."
            .TrailingCharacter = wdTrailingTab
            .NumberStyle = wdListNumberStyleArabic
            .NumberPosition = CentimetersToPoints(0.63)
            .Alignment = wdListLevelAlignLeft
            .TextPosition = CentimetersToPoints(1.27)
            .TabPosition = CentimetersToPoints(1.27)
            .ResetOnHigher = 0
            .StartAt = 1
            With .Font
                .Bold = wdUndefined
                .Italic = wdUndefined
                .StrikeThrough = wdUndefined
                .Subscript = wdUndefined
                .Superscript = wdUndefined
                .Shadow = wdUndefined
                .Outline = wdUndefined
                .Emboss = wdUndefined
                .Engrave = wdUndefined
                .AllCaps = wdUndefined
                .Hidden = wdUndefined
                .Underline = wdUndefined
                .Color = wdUndefined
                .Size = wdUndefined
                .Animation = wdUndefined
                .DoubleStrikeThrough = wdUndefined
                .Name = ""
            End With
            .LinkedStyle = ""
        End With
        ListGalleries(wdNumberGallery).ListTemplates(1).Name = ""
        Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
            wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
            wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
        Selection.TypeBackspace
        Selection.WholeStory
        With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
            .NumberFormat = "%1."
            .TrailingCharacter = wdTrailingTab
            .NumberStyle = wdListNumberStyleArabic
            .NumberPosition = CentimetersToPoints(0.63)
            .Alignment = wdListLevelAlignLeft
            .TextPosition = CentimetersToPoints(1.27)
            .TabPosition = CentimetersToPoints(1.27)
            .ResetOnHigher = 0
            .StartAt = 1
            With .Font
                .Bold = wdUndefined
                .Italic = wdUndefined
                .StrikeThrough = wdUndefined
                .Subscript = wdUndefined
                .Superscript = wdUndefined
                .Shadow = wdUndefined
                .Outline = wdUndefined
                .Emboss = wdUndefined
                .Engrave = wdUndefined
                .AllCaps = wdUndefined
                .Hidden = wdUndefined
                .Underline = wdUndefined
                .Color = wdUndefined
                .Size = wdUndefined
                .Animation = wdUndefined
                .DoubleStrikeThrough = wdUndefined
                .Name = ""
            End With
            .LinkedStyle = ""
        End With
        ListGalleries(wdNumberGallery).ListTemplates(1).Name = ""
        Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
            wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
            wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
    j' essaye avec ListTemplate et ses propriétés mais aucun resultat

    Merci de votre aide

  2. #2
    Membre confirmé
    Profil pro
    Administrateur réseau
    Inscrit en
    Mai 2009
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Administrateur réseau

    Informations forums :
    Inscription : Mai 2009
    Messages : 58
    Par défaut
    J'ai trouvé la solution

    Il faut d'abord définir une "ListTemplate" et l'associer au document word créé, puis une "Globalclass" pour personnaliser (position text...)la numérotation que va produire la "ListTemplate".

    Enfin, on applique la numérotation au texte ou paragraphe voulu avec "ListFormat".

    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
     
    object derniereligne = true;
                object nomlist = "numdoc";
                object index1 = 0;
     
     
     
     
                ListTemplate lt = docword.ListTemplates.Add(ref derniereligne, ref nomlist);
                GlobalClass gc = new GlobalClass();
     
     
                for (int i = 1; i < 3; i++)
                {
     
                    lt.ListLevels[i].NumberStyle = (WdListNumberStyle)index1;
                    lt.ListLevels[i].TextPosition = gc.CentimetersToPoints((float)1.27);
                    lt.ListLevels[i].TrailingCharacter = 0;
                    lt.ListLevels[i].NumberPosition = gc.CentimetersToPoints((float)0.63);
                    lt.ListLevels[i].TabPosition = gc.CentimetersToPoints((float)1.27);
                    lt.ListLevels[i].Alignment = 0;
                    lt.ListLevels[i].StartAt = 1;
                    lt.ListLevels[i].ResetOnHigher = i - 1;
     
     
                }
     
                lt.ListLevels[1].NumberFormat = "%1.";
                lt.ListLevels[2].NumberFormat = "%2.";
                lt.ListLevels[3].NumberFormat = "%3.";
     
     
     
    object param = System.Reflection.Missing.Value;
     
    modal1.Range.ListFormat.ApplyListTemplate(lt, ref param, ref param, ref param);
    Si sa peut aider d'autres

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Automation Word] Texte en Gras
    Par uskiki85 dans le forum Access
    Réponses: 1
    Dernier message: 07/10/2005, 22h51
  2. [MFC] - Automation Word bug
    Par Alice9 dans le forum MFC
    Réponses: 3
    Dernier message: 25/05/2005, 17h47
  3. [C#] [Automation Word] Récupérer la valeur d'une cellule
    Par Ditch dans le forum Windows Forms
    Réponses: 2
    Dernier message: 16/06/2004, 16h57
  4. Automation Word
    Par afan dans le forum MFC
    Réponses: 8
    Dernier message: 12/11/2003, 15h50
  5. [AUTOMATION WORD]Pilotage Word par Delphi
    Par Sunny dans le forum API, COM et SDKs
    Réponses: 5
    Dernier message: 05/12/2002, 18h09

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