Page 1 sur 1
[R] Ecrire dans un document Word
Posté : mer. 29 avr. 2015 16:36
par jcaspar
B
onjour à tous !
Je souhaiterais pouvoir écrire du texte dans Word en passant par Autoit
mais il me semble qu'il n'existe pas de fonction dédiée à cet effet est il malgré tout possible d'y parvenir ?
Exemple la variable Nom=toto je souhaiterais écrire Toto dans Word
Je vous remercie d'avance pour vos conseils
Jean-Marc
Re: [..] Ecrire dans un document Word
Posté : mer. 29 avr. 2015 17:28
par Hugues
Salut,
Un exemple vite fait:
► Afficher le texte
Code : Tout sélectionner
#include <MsgBoxConstants.au3>
#include <Word.au3>
$oWord = _Word_Create(False, True)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, " ", "Erreur de création document Word." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;On ouvre le fichier Word
$oDoc = _Word_DocOpen($oWord, "c:\temp\Print.doc", Default, Default, True)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Impression courbe", "Erreur d'ouverture 'Print.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$mavariable = "test de saisie"
$mavariable2 = "test de saisie 2"
$oRange = _Word_DocRangeSet($oDoc, -1)
Dim $asArray[2] = [$mavariable, $mavariable2]
_Word_DocTableWrite($oRange, $asArray, 0)
Re: [..] Ecrire dans un document Word
Posté : jeu. 30 avr. 2015 09:06
par walkson
Bonjour,
Un autre exemple...
WordConstants.au3 vient de
http://www.autoitscript.com/forum/topic ... tants-udf/ qui est plus complet
► Afficher le texte
Code : Tout sélectionner
#include "WordConstants.au3"
$nom = "toto"
$word = ObjCreate("Word.Application")
$word.visible = True
$word.Documents.Add
$wordopen = $word.ActiveDocument
$bb = $wordopen.content
$matable = $wordopen.Tables.Add($bb, 3, 3,Default,Default)
For $i = 1 To 3
For $y = 1 To 3
$matable.Cell($i,$y).Range.InsertAfter ($i & $y)
$matable.Cell($i,$y).Select
$word.Selection.Cells.VerticalAlignment = $wdCellAlignVerticalCenter
$word.Selection.ParagraphFormat.Alignment = $wdAlignParagraphCenter
With $word.Selection.Cells.Borders($wdBorderLeft)
.LineStyle = $wdLineStyleSingle
.LineWidth = $wdLineWidth300pt
.Color = $wdColorWhite
EndWith
With $word.Selection.Cells.Borders($wdBorderRight)
.LineStyle = $wdLineStyleSingle
.LineWidth = $wdLineWidth300pt
.Color = $wdColorOliveGreen
EndWith
With $word.Selection.Cells.Borders($wdBorderTop)
.LineStyle = $wdLineStyleSingle
.LineWidth = $wdLineWidth300pt
.Color = $wdColorOrange
EndWith
With $word.Selection.Cells.Borders($wdBorderBottom)
.LineStyle = $wdLineStyleSingle
.LineWidth = $wdLineWidth300pt
.Color = $wdColorDarkBlue
EndWith
Next
$wordopen.Tables(1).Rows(1).Cells($i).Shading.Texture = $wdTexture20Percent
$wordopen.Tables(1).Rows(2).Cells($i).Shading.BackgroundPatternColor= $wdColorGold
$wordopen.Tables(1).Rows(3).Cells($i).Shading.Texture = $wdTextureDiagonalDown
Next
MsgBox(64,"","Tableau formatté",3)
$matable.Cell(3,3).Select
$word.Selection.InsertCells ($wdInsertCellsShiftRight)
MsgBox(64,"","Nouvelle Cell",3)
$wordopen.Tables(1).Cell(3, 4).Delete
MsgBox(64,"","Cell détruite",3)
$wordopen.Tables(1).ConvertToText ($wdSeparateByTabs)
MsgBox(64,"","Tableau en texte",3)
$debut = $wordopen.Paragraphs(1).Range.Start
$fin = $wordopen.Paragraphs(3).Range.End
$wordopen.Range($debut,$fin).Select
$matable = $word.Selection.ConvertToTable($wdSeparateByTabs,Default,Default,100,$wdTableFormatColorful1, _
Default,Default,Default,Default,Default,Default,Default,Default,True,$wdWord9TableBehavior,$wdAutoFitFixed)
MsgBox(64,"","texte en tableau",3)
$matable.Cell(3, 3).AutoSum
$matable.Cell(3,3).Select
$xx = $word.Selection.Text
$wordopen.Range.insertAfter("somme C1 + C2 = " & $xx)
$wordopen.Range.insertAfter("FINI...." )
$wordopen.Range.insertAfter($nom )