Vb.net aligner l'equation dans word à gauche

Résolu
kikou93 Messages postés 417 Date d'inscription mardi 4 février 2014 Statut Membre Dernière intervention 24 septembre 2018 - Modifié par kikou93 le 7/08/2016 à 19:42
kikou93 Messages postés 417 Date d'inscription mardi 4 février 2014 Statut Membre Dernière intervention 24 septembre 2018 - 8 août 2016 à 21:26
Bonjour,
je demande votre aide pour le sujet suivant :
avec l'aide Whismeril (Merci Whismeril ) j'ai pu savoir comment faire pour écrire une équation dans Word à l'aide de Visual basic express 2010
maintenant je veux aligner l'équation à gauche, normalement le code utilisé est celui-ci non :
objEq1.ParentOMath.Justification = WdOMathJc.wdOMathJcLeft 

on le place ici :
Dim rng1 As Word.Range = oDoc.Range() 
rng1 = oDoc.Content.OMaths.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
var = FormatNumber(CDbl(TextBox1.Text), 2) * 100
rng1.Text = "L/15 " + ChrW(10877) + " h " + ChrW(10877) + _
" L/10 " + ChrW(8594) + " " & var & "/15 " + ChrW(10877) + " h " + ChrW(10877) & var & "/10 " + ChrW(8594) + " h = " & Label11.Text & " cm "
rng1.Font.Bold = False
rng1.Font.Italic = False
rng1.Font.Name = "Georgia"
rng1.Font.Color = WdColor.wdColorBlack
rng1.OMaths.Add(rng1)
Dim objEq1 As OMath = rng1.OMaths(1)
objEq1.ParentOMath.Justification = WdOMathJc.wdOMathJcLeft
objEq1.BuildUp()


quand je lance le programme aucune erreur ne s'affiche
mais l’équation ne s'aligne pas à gauche
remarque :
j'ai converti le code utilisé par le langage VBA (celui de Word)
Merci de bien vouloir m'aider

Comment ça marche c'est cool! 
      1000 Merci les Amis

1 réponse

kikou93 Messages postés 417 Date d'inscription mardi 4 février 2014 Statut Membre Dernière intervention 24 septembre 2018 1
8 août 2016 à 11:30
Bonjour ,

aprés quelque essais, j'ai remarqué 3 choses :
1er mot, si j'écris dans :
La 1er ligne un texte
La 2ème ligne une équation
Remarque :
l'équation est aligné a gauche

le code :

        oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "1er titre :"
oPara1.Range.Font.Bold = True
oPara1.Range.Font.Italic = False
oPara1.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
oPara1.Range.Font.Name = "Georgia"
oPara1.Range.Font.Color = WdColor.wdColorRed
oPara1.Format.SpaceAfter = 15
oPara1.Range.InsertParagraphAfter()
'*...............................
Dim rng1 As Word.Range = oDoc.Range()
rng1 = oDoc.Content.OMaths.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
rng1.Text = "L/15 " + ChrW(10877) + " L/17 "
rng1.Font.Bold = False
rng1.Font.Italic = False
rng1.Font.Name = "Georgia"
rng1.Font.Color = WdColor.wdColorBlack
rng1.OMaths.Add(rng1)
Dim objEq1 As OMath = rng1.OMaths(1)
objEq1.ParentOMath.Justification = WdOMathJc.wdOMathJcLeft
objEq1.BuildUp()



2ème mot si j'écris dans :
La 1er ligne un texte
La 2ème ligne une équation
La 3ème ligne une équation
Remarque :
La 1er équation est aligné au centre
La 2ème équation est aligné a gauche
Le code :
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "1er titre :"
oPara1.Range.Font.Bold = True
oPara1.Range.Font.Italic = False
oPara1.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
oPara1.Range.Font.Name = "Georgia"
oPara1.Range.Font.Color = WdColor.wdColorRed
oPara1.Format.SpaceAfter = 15
oPara1.Range.InsertParagraphAfter()
'*...............................
Dim rng1 As Word.Range = oDoc.Range()
rng1 = oDoc.Content.OMaths.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
rng1.Text = "L/15 " + ChrW(10877) + " L/17 "
rng1.Font.Bold = False
rng1.Font.Italic = False
rng1.Font.Name = "Georgia"
rng1.Font.Color = WdColor.wdColorBlack
rng1.OMaths.Add(rng1)
Dim objEq1 As OMath = rng1.OMaths(1)
objEq1.ParentOMath.Justification = WdOMathJc.wdOMathJcLeft
objEq1.BuildUp()
'*...............................
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.ParagraphFormat.SpaceAfter = 6
oRng.InsertAfter("")
oRng.InsertParagraphAfter()
'*...............................
Dim rng2 As Word.Range = oDoc.Range()
rng2 = oDoc.Content.OMaths.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
rng2.Text = "L/15 " + ChrW(10877) + " L/29 "
rng2.Font.Bold = False
rng2.Font.Italic = False
rng2.Font.Name = "Georgia"
rng2.Font.Color = WdColor.wdColorBlack
rng2.OMaths.Add(rng2)
Dim objEq2 As OMath = rng2.OMaths(1)
objEq2.ParentOMath.Justification = WdOMathJc.wdOMathJcLeft
objEq2.BuildUp()


3ème mot si j'écris dans :
La 1er ligne un texte
La 2ème ligne une équation
La 3ème ligne une équation
La 4ème ligne un texte
Remarque :
La 1er équation est aligné au centre
La 2ème équation est aligné au centre
je n'arrive pas à comprendre pourquoi si j'ajoute un texte (ou équation) après une équation sont alignement (à gauche) s'annule
0
kikou93 Messages postés 417 Date d'inscription mardi 4 février 2014 Statut Membre Dernière intervention 24 septembre 2018 1
Modifié par kikou93 le 8/08/2016 à 21:26
salut j'ai fini par trouver une solution
comme je n'arrivé pas à trouver une solution dans internet, j'ai essayé plusieur combinaisons
voici le code :
oWord.ActiveDocument.OMathJc = WdOMathJc.wdOMathJcLeft

et en bonus le code qui permet de rendre le texte de l'équation non Italique et aussi de changer la police par défaut (Cambria Math) de l'équation
oWord.Selection.EndKey(Word.WdUnits.wdStory)
oWord.Selection.HomeKey(Word.WdUnits.wdStory, Word.WdKey.wdKeyShift)
oWord.Selection.Font.Italic = False
oWord.Selection.Font.Name = "Georgia"
0
Rejoignez-nous