KenzoIT Posted December 19, 2009 Share Posted December 19, 2009 Hi everyone,I don't know how to insert a full text from a word document to a frame.This is my code :#include <GUIConstantsEx.au3>#include <GuiButton.au3>#include <WindowsConstants.au3>#include <TreeViewConstants.au3>#include <StaticConstants.au3>#include <Word.au3>Opt("MustDeclareVars", 1)Global $iMemo, $iRandGlobal $hGui = GUICreate("AutoIT",750, 650,-1,-1)Global $sFilePath1 = "D:\Test\Command.doc"GUICtrlSetColor(-1, 0x0000CC)GUICtrlSetFont(-1, 11.5, 600)Local $oWordApp = ObjCreate("Word.Application")Local $treeviewLocal $insert, $gs1, $gs2, $gs3Local $a1, $a2, $a3, $a4, $b1, $b2, $b3, $b4_Main()Func _Main() $iMemo = GUICtrlCreateEdit("", 200, 40, 540, 600, 0) GUICtrlCreateLabel("AutoIT Forums",420,10,400,30) GUICtrlSetFont(-1,16,12) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1,0xff00ee) GUICtrlSetCursor(-1,0) $treeview = GUICtrlCreateTreeView(10, 40, 170, 600, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $insert = GUICtrlCreateTreeViewItem("Open Word Document", $treeview) GUICtrlSetColor(-1, 0x0000C0) $gs1=GUICtrlCreateTreeViewItem("GS1",$insert) GUICtrlSetColor(-1, 0x0000CC) $gs2=GUICtrlCreateTreeViewItem("GS2",$insert) GUICtrlSetColor(-1, 0x0000C0) $gs3=GUICtrlCreateTreeViewItem("GS3",$insert) GUICtrlSetColor(-1, 0x0000C0) GUICtrlSetState($insert, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) GUICtrlSetState($gs1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) GUICtrlSetState($gs2, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) GUICtrlSetState($gs3, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) $a1 = GUICtrlCreateTreeViewItem("AutoIT-1", $gs1) $a2 = GUICtrlCreateTreeViewItem("AutoIT-2", $gs1) $a3 = GUICtrlCreateTreeViewItem("AutoIT-3", $gs1) $a4 = GUICtrlCreateTreeViewItem("AutoIT-4",$gs1) $b1 = GUICtrlCreateTreeViewItem("AutoIT-A",$gs2) $b2 = GUICtrlCreateTreeViewItem("AutoIT-B",$gs2) $b3 = GUICtrlCreateTreeViewItem("AutoIT-C",$gs3) $b4 = GUICtrlCreateTreeViewItem("AutoIT-D",$gs3)GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _WordDocClose($oWordApp,0) ExitLoop Case $a1 $oWordApp = _WordDocOpen($sFilePath1,0) EndSwitch WEnd ExitEndFuncFunc MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)EndFuncPls, help me solve the problem.Many thanks ! Link to comment Share on other sites More sharing options...
Authenticity Posted December 19, 2009 Share Posted December 19, 2009 expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <StaticConstants.au3> #include <Word.au3> Opt("MustDeclareVars", 1) Global $iMemo, $iRand Global $hGui = GUICreate("AutoIT", 750, 650, -1, -1) Global $sFilePath1 = "D:\Test\Command.doc" GUICtrlSetColor(-1, 0x0000CC) GUICtrlSetFont(-1, 11.5, 600) Local $oWordApp = ObjCreate("Word.Application") Local $oWordDoc Local $treeview Local $insert, $gs1, $gs2, $gs3 Local $a1, $a2, $a3, $a4, $b1, $b2, $b3, $b4 _Main() Func _Main() $iMemo = GUICtrlCreateEdit("", 200, 40, 540, 600, 0) GUICtrlCreateLabel("AutoIT Forums", 420, 10, 400, 30) GUICtrlSetFont(-1, 16, 12) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xff00ee) GUICtrlSetCursor(-1, 0) $treeview = GUICtrlCreateTreeView(10, 40, 170, 600, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $insert = GUICtrlCreateTreeViewItem("Open Word Document", $treeview) GUICtrlSetColor(-1, 0x0000C0) $gs1 = GUICtrlCreateTreeViewItem("GS1", $insert) GUICtrlSetColor(-1, 0x0000CC) $gs2 = GUICtrlCreateTreeViewItem("GS2", $insert) GUICtrlSetColor(-1, 0x0000C0) $gs3 = GUICtrlCreateTreeViewItem("GS3", $insert) GUICtrlSetColor(-1, 0x0000C0) GUICtrlSetState($insert, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) GUICtrlSetState($gs1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) GUICtrlSetState($gs2, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) GUICtrlSetState($gs3, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) $a1 = GUICtrlCreateTreeViewItem("AutoIT-1", $gs1) $a2 = GUICtrlCreateTreeViewItem("AutoIT-2", $gs1) $a3 = GUICtrlCreateTreeViewItem("AutoIT-3", $gs1) $a4 = GUICtrlCreateTreeViewItem("AutoIT-4", $gs1) $b1 = GUICtrlCreateTreeViewItem("AutoIT-A", $gs2) $b2 = GUICtrlCreateTreeViewItem("AutoIT-B", $gs2) $b3 = GUICtrlCreateTreeViewItem("AutoIT-C", $gs3) $b4 = GUICtrlCreateTreeViewItem("AutoIT-D", $gs3) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE If IsObj($oWordDoc) Then _WordDocClose($oWordDoc, 0) _WordQuit($oWordApp, 0) ExitLoop Case $a1 $oWordDoc = _WordDocOpen($oWordApp, $sFilePath1) If IsObj($oWordDoc) Then MemoWrite(StringReplace($oWordDoc.Content.Text, @CR, @CRLF)) EndSwitch WEnd Exit EndFunc ;==>_Main Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF) EndFunc ;==>MemoWrite Link to comment Share on other sites More sharing options...
KenzoIT Posted December 20, 2009 Author Share Posted December 20, 2009 Thanks for your support Link to comment Share on other sites More sharing options...
KenzoIT Posted December 20, 2009 Author Share Posted December 20, 2009 (edited) Hi Authenticity, There are some incidents when I run your code. 1. A picture that insert a document can not show a picture in a frame. 2. When I select AutoIT-1, AutoIT-2 or... from two or more times. These documents will be automatically opened. If I close documents, the code fail. I spend a lot of time to fix errors but it doesn't work Can you help me fix the errors ? Thanks ! Edited December 21, 2009 by KenzoIT Link to comment Share on other sites More sharing options...
KenzoIT Posted December 21, 2009 Author Share Posted December 21, 2009 Anyone help me ? Link to comment Share on other sites More sharing options...
Authenticity Posted December 21, 2009 Share Posted December 21, 2009 If you don't want to deal with the document format you can save the document as a .htm file and load it in internet explorer: #include <GUIConstantsEx.au3> #include <IE.au3> #include <Word.au3> Local $hGUI, $oWordApp, $oWordDoc, $oIE, $Ctrl $oWordApp = ObjCreate("Word.Application") $oWordDoc = _WordDocOpen($oWordApp, @ScriptDir & "\test.doc") _WordDocSaveAs($oWordDoc, @ScriptDir & "\test.htm", 10) $oIE = _IECreateEmbedded() $hGUI = GUICreate("Title", 700, 400) $Ctrl = GUICtrlCreateObj($oIE, 140, 10, 550, 380) _IENavigate($oIE, "file:///" & @ScriptDir & "\test.htm") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WordQuit($oWordApp, 0) GUIDelete() Exit Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now