Sign in to follow this  
Followers 0
Necromorph

Edit a rich text document

5 posts in this topic

#1 ·  Posted (edited)

I keep trying to make my project easier, by eliminating this hurdle, but there just is no way around it. i need to edit a rich text document. i tried to make the entire document in autoit, by using FileWriteLine() and coding in rtf. but, insterting a graphic was near impossiable. now i made an rtf 'template' with the graphic in it. but i need to edit the first few lines, with changing data. and of corse, i cant do this with FileWriteLine(), or _FileWriteToLine(), and i can't get any of the Word.au3 UDF's to work. Im just wondering the simplist solution to adding 2 to 6 lines of text to the top of an already existing rich text document. thanks.

Edited by redLabel

Share this post


Link to post
Share on other sites



I created a Test1.rtf file, with one line of text, a graphic, then another line of text:

This is before the graphic.

<image here>

This is after the graphic.

Then I ran this script against it, and it worked fine:

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>

Global $hGUI, $hRTE, $sRTF = @ScriptDir & "\Test1.rtf", $aPos

$hGUI = GUICreate("Test", 500, 500)
$hRTE = _GUICtrlRichEdit_Create($hGUI, "", 20, 20, 460, 360)
GUISetState()

Sleep(2000)

_GUICtrlRichEdit_StreamFromFile($hRTE, $sRTF)

Sleep(2000)

$aPos = _GUICtrlRichEdit_FindTextInRange($hRTE, "before", 0, 20)
_GuiCtrlRichEdit_SetSel($hRTE, $aPos[0], $aPos[1])
_GUICtrlRichEdit_ReplaceText($hRTE, "_BEFORE_")

Sleep(2000)

_GUICtrlRichEdit_StreamToFile($hRTE, @ScriptDir & "\Test1_New.rtf")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRTE)
            Exit
    EndSwitch
WEnd

Changed the text in the first line to "This is _BEFORE_ the graphic." and saved it to the Test1_New.rtf file.

So if you can create a template with the graphic already in it, the GuiRichEdit.au3 UDF functions can manipulate the text around it just fine.

:x


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thank you very much for you help, i modded it a lot, but the concept is the same. i lost the While statement, and never show the GUI, so it Just makes it. but thank you all the same. when my code is fully finished, i will post it. thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This maybe a differnt post, but ill start here, how do i make the _GUICtrlRichEdit_SetAttribute() work for email address, the '+li' doesnt seem to be working. and i know that rtf supports this. any ideas?

_GUICtrlRichEdit_GoToCharPos($hCtrl, 0)
_GUICtrlRichEdit_SetAttribute($hCtrl, '+li') ;==>this doesnt seem to work
_GUICtrlRichEdit_InsertText($hCtrl, 'user@domain.com' & @LF)

if you open the RTF afterwards, and hit 'Enter' after the line, it will make it a "hyperlink", but i don't want to open the doc. send and {ENTER} and close it. there must be a better way.

Edited by redLabel

Share this post


Link to post
Share on other sites

Try selecting the text, then set the attribute on the selection. Should be more reliable that way.

:x


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0