luis713 Posted October 2, 2018 Posted October 2, 2018 Hello everyone, I'm using a GuiCtrlRichEdit and I have changed the spacing but I need to read it and save the information to a word document, I can save the document but spacing changes. When I copy manually the information from the control and paste it on word it works perfectly but I don't know what command I should use to copy the text without changing the format expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <word.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 600, 600) Local $idSave = GUICtrlCreateButton("Save", 10, 570, 85, 25) Local $idSpacing = GUICtrlCreateButton("Spacing", 200, 570, 85, 25) Global $RichEdit = _GUICtrlRichEdit_Create($hGui, "test", 10, 10, 500, 500, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idSave Global $File = FileSaveDialog("Choose a location", @DesktopDir, "Microsoft Word (*.docx)|PDF (*.pdf)|RTF (*.rtf)", $FD_PROMPTOVERWRITE) Local $Extension = StringRight($File, 4) If $Extension = "docx" Then SaveWord($File) Case $idSpacing _GUICtrlRichEdit_SetParaSpacing($RichEdit, 0, .8) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func SaveWord($SaveFile = @DesktopDir & "\Word.docx") Local $oWord If Not ProcessExists("winword.exe") Then $oWord = _Word_Create(@SW_HIDE) Else $oWord = _Word_Create() EndIf ; Open the test document Local $oDoc = _Word_DocOpen($oWord, @TempDir & "\Word.docx") If @error Then MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSave Example", "Error opening Word." & @CRLF & "error = " & @error & ", @extended = " & @extended) Else ; Save the document ; Insert text at the beginning Local $oRange = _Word_DocRangeSet($oDoc, -1) Local $Text = _GUICtrlRichEdit_GetText($RichEdit) $oRange.Text = $Text; ; Save document _Word_DocSaveAs($oDoc, $SaveFile) EndIf EndFunc
mikell Posted October 3, 2018 Posted October 3, 2018 You might try _GUICtrlRichEdit_StreamToFile This works for me : expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 600, 600) Local $idSave = GUICtrlCreateButton("Save", 10, 570, 85, 25) Local $idSpacing = GUICtrlCreateButton("Spacing", 200, 570, 85, 25) Global $RichEdit = _GUICtrlRichEdit_Create($hGui, "test", 10, 10, 500, 500, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idSave Global $File = FileSaveDialog("Choose a location", @DesktopDir, "RTF (*.rtf)", $FD_PROMPTOVERWRITE) SaveWord($file) Case $idSpacing _GUICtrlRichEdit_SetParaSpacing($RichEdit, 0, .8) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func SaveWord($file) _GUICtrlRichEdit_StreamToFile($RichEdit, $file) EndFunc
luis713 Posted October 3, 2018 Author Posted October 3, 2018 Thanks for replying Mikell, I have part of my code streamtofile and saves the text in rtf, do you know if it can save it as word keeping the format? I was looking into word api but it is my first time managing objects, I willing to learn about objects if somebody knows a topic or link to read about them would be great
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