Jump to content
Sign in to follow this  
qUser4eva

Clipboard data in HTML format.

Recommended Posts

qUser4eva

How can I get and set the clipboard data using HTML?

E.g. user copies this text from webpage: Hello world.

AutoIt reads the clipboard as

<b>Hello world.</b>
.

Thanks!

Share this post


Link to post
Share on other sites
nerdgerl

How can I get and set the clipboard data using HTML?

E.g. user copies this text from webpage: Hello world.

AutoIt reads the clipboard as

<b>Hello world.</b>
.

Thanks!

$newstring = "<B>" & ClipGet() & "</B>"

My AutoIT's:[topic="53958"]Personal Encyclopedia/Dictionary[/topic][topic="46311"]MS Access (Style) Database[/topic]"Some people are born on third base and go through life thinking they hit a triple."

Share this post


Link to post
Share on other sites
qUser4eva

Thanks for the response. I was essentially asking how to read data with its HTML preserved from the clipboard; I'm not trying to add my own.

For instance, the user would press Ctrl+A (select all) and then Ctrl+C (copy) in firefox, and AutoIt could read the rendered HTML page source from the clipboard.

Thanks in advance.

Edited by qUser4eva

Share this post


Link to post
Share on other sites
nerdgerl

Thanks for the response. I was essentially asking how to read data with its HTML preserved from the clipboard; I'm not trying to add my own.

For instance, the user would press Ctrl+A (select all) and then Ctrl+C (copy) in firefox, and AutoIt could read the rendered HTML page source from the clipboard.

Thanks in advance.

HA! I knew the question was too easy! I read it wrong!! LoL


My AutoIT's:[topic="53958"]Personal Encyclopedia/Dictionary[/topic][topic="46311"]MS Access (Style) Database[/topic]"Some people are born on third base and go through life thinking they hit a triple."

Share this post


Link to post
Share on other sites
Nahuel

IF I'm not wrong, Firefox has that option built-in (It's either Firefox or Opera).

It could be possible... perhaps using ClipGet() (or the _Clipboard*() functions for more advanced options) and _InetGetSource(). The only problem I can think of right now is how to make the script know where the HTML code of that part starts and where it ends.

Share this post


Link to post
Share on other sites
qUser4eva

Although, I'm sure how to do it, I think the best approach would be to use _ClipBoard_GetData([$iFormat = 1]), and somehow pass "HTML" as $iFormat to the function. How do I do that? thanks.

Edited by qUser4eva

Share this post


Link to post
Share on other sites
qazwsx

maybe you could read the pages source to a variable. Then find the text which is selected and take all of the html tags associated with it from the source. Fairly roundabout, but im not sure if another solution has been found.

Share this post


Link to post
Share on other sites
larryc

I think I answered my own question. I had to bastardize the _clipboard_setdata function, but it appears to be working. Running this script will put HTML formatted data onto the clipboard, which can then be pasted into an application such as Email, Word, etc.

CODE

#include <ClipBoard.au3>

; Open the clipboard

If Not _ClipBoard_Open (0) Then msgbox (0,'Error',"_ClipBoard_Open failed")

$iFormat = _ClipBoard_RegisterFormat ("HTML Format")

If $iFormat = 0 Then msgbox(0,'',"_ClipBoard_RegisterFormat failed")

;msgbox(0,'','$iformat is ' & $iFormat)

$i = _ClipBoard_GetData($iFormat)

;msgbox(0,'$i is',$i)

$m_sDescription = _

"Version:1.0" & @CrLf & _

"StartHTML:aaaaaaaaaa" & @CrLf & _

"EndHTML:bbbbbbbbbb" & @CrLf & _

"StartFragment:cccccccccc" & @CrLf & _

"EndFragment:dddddddddd" & @CrLf

$sStart = "<HTML><BODY><FONT FACE=Arial SIZE=1 COLOR=BLUE>"

$sFrag = '<B>This is bold</B> and <I>this is italic.</I> And this is a <a href="http://www.yahoo.com">hyperlink</a>'

$sEnd = "</FONT></BODY></HTML>"

;msgbox(0,'test',stringFormat( "%010s",stringLen($m_sDescription)))

$sData = $m_sDescription & $sStart & $sFrag & $sEnd

$sData = stringReplace($sData, "aaaaaaaaaa", stringFormat("%010s",stringLen($m_sDescription)))

$sData = stringReplace($sData, "bbbbbbbbbb", stringFormat("%010s",stringLen($sData)))

$sData = stringReplace($sData, "cccccccccc", stringFormat("%010s",stringLen($m_sDescription & $sStart)))

$sData = stringReplace($sData, "dddddddddd", stringFormat("%010s",stringLen( $m_sDescription & $sStart & $sFrag)))

;msgbox(0,'sdata',$sData)

if (my_ClipBoard_SetData($sData,$iformat,1) == 0 ) then msgbox(0,'Error','Error putting data on clipboard')

_ClipBoard_Close()

Func My_ClipBoard_SetData($vData, $iFormat = 1,$force = 0)

Local $tData, $hLock, $hMemory, $iSize

If ($force ==1) Then

$iSize = StringLen($vData) + 1

$hMemory = _MemGlobalAlloc($iSize, $GHND)

If $hMemory = 0 Then Return SetError(-1, 0, 0)

$hLock = _MemGlobalLock($hMemory)

If $hLock = 0 Then Return SetError(-2, 0, 0)

$tData = DllStructCreate("char Text[" & $iSize & "]", $hLock)

DllStructSetData($tData, "Text", $vData)

_MemGlobalUnlock($hMemory)

Else

; Assume all other formats are a pointer or a handle (until users tell me otherwise) :)

$hMemory = $vData

EndIf

If Not _ClipBoard_Open(0) Then Return SetError(-5, 0, 0)

If Not _ClipBoard_Empty() Then Return SetError(-6, 0, 0)

If Not _ClipBoard_SetDataEx($hMemory, $iFormat) Then

_ClipBoard_Close()

Return SetError(-7, 0, 0)

EndIf

_ClipBoard_Close()

Return $hMemory

EndFunc ;==>my_ClipBoard_SetData

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.