Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Convert clipboard data to HTML


  • Please log in to reply
14 replies to this topic
beetle120
  • Guests
  • Last active:
  • Joined: --
Hi I am new to AutoHotkey. Just want to know if is it possible to convert text from MS Word text in the clipboard to HTML code to put into a string. I would like to have the same sort of text that can be generated if you paste the text from Word in to the design tab in Dreamweaver and then view the code it generates.

Is this possible and if so how is it done?

Thanks

beetle120
  • Guests
  • Last active:
  • Joined: --
#bump#[/i]

a4u
  • Guests
  • Last active:
  • Joined: --
Probably can be done. Do you have an example of what you want?

beetle120
  • Guests
  • Last active:
  • Joined: --

Probably can be done. Do you have an example of what you want?

Thanks for you response. At my work we have an in house program that uses a simple HTML editor. All of the work that we put into this program is from Word that we copy/paste and manually format ourself adding all the
  • and some class tags to match the formatting in the Word document (a very time consuming task). What I am thinking, to speed up this process, is from the clipboard (from the copy) find and replace the Word formatting using AutoHotkey to the simple HTML and the other tags we use before putting the string back in the clipboard ready for the paste.

    I am not sure of the method that that windows uses to copy formatting to the clipboard. I am hoping that it is possible to get access to the HTML formatted text like what Dreamweaver has when you copy a word document in, so it would be easy to use find/replace to convert to simple HTML.


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
SetClipboardData and GetClipboardData functions by PhiLho

The keyword that you need: HTML Format

GetClipboardData( "[color=darkred]HTML Format[/color]", Data )
VarSetCapacity( Data, -1 )
MsgBox, % Data


beetle120
  • Guests
  • Last active:
  • Joined: --
Thanks a lot for that, I will give it a shot when a get a chance.

beetle120
  • Guests
  • Last active:
  • Joined: --
OK I am still confused. I feel like I am jumping in the deep end without first learning how to swim.

If I wanted to get copied part of a Word document's HTML into a message box what code do I need? Do I need more then one .ahk file or can they link if so how (you can tell that I am completely new at this). All I have got so far is an empty message box and a message box containing unusable gibberish.

Thanks a lot.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Post whatever you have tried.. Ask-for-help topic cannot continue without actual code.
kWo4Lk1.png

beetle120
  • Members
  • 4 posts
  • Last active: Oct 20 2010 05:28 AM
  • Joined: 20 Oct 2010
All I have so far is the Set and Get of the ClipboardData function and the included message boxes that was in a earlier post

[color=#909BAB][ Moderator!: Edited out ][/color]

The first two message boxes are blank and the 3rd has gibberish when I copy a word document or just blank when copying from a text document.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

3rd has gibberish


When the msgbox is active, you can do a ctrl+c to copy the msgbox contents to the clipboard.

Post the 'gibberish' here.

For example: When I copy the last two lines of your previous post, this is what I get:

---------------------------
Gui0.ahk
---------------------------
Version:0.9

StartHTML:0000000170

EndHTML:0000001080

StartFragment:0000000208

EndFragment:0000001042

SourceURL:http://www.autohotkey.com/forum/viewtopic.php?t=63672

<html>

<body>

<!--StartFragment-->

<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px; ">[color=blue]The first two message boxes are blank and the 3rd has gibberish when I copy a word document or just blank when copying from a text document.[/color]</span></span>

<!--EndFragment-->

</body>

</html>
---------------------------
OK   
---------------------------


beetle120
  • Members
  • 4 posts
  • Last active: Oct 20 2010 05:28 AM
  • Joined: 20 Oct 2010
What I get when I copy the same 2 lines it is:

---------------------------
Test.ahk
---------------------------
敖獲潩㩮⸰ഹ匊慴瑲呈䱍〺〰〰〰㜱സ䔊摮呈䱍〺〰〰㄰㤰ല匊慴瑲牆条敭瑮〺〰〰〰ㄲശ䔊摮牆条敭瑮〺〰〰㄰㔰ഴ匊畯捲啥䱒栺瑴㩰⼯睷⹷畡潴潨歴祥挮浯是牯浵瘯敩瑷灯捩瀮灨瀿㌽㈹㈳⌱㤳㌲ㄲ਍格浴㹬਍戼摯㹹਍ℼⴭ瑓牡䙴慲浧湥⵴㸭਍猼慰汣獡㵳䄢灰敬猭祴敬猭慰≮猠祴敬∽潢摲牥挭汯慬獰㩥猠灥牡瑡㭥挠汯牯›杲⡢ⰰ〠‬⤰※潦瑮昭浡汩㩹✠楔敭⁳敎⁷潒慭❮※潦瑮猭祴敬›潮浲污※潦瑮瘭牡慩瑮›潮浲污※潦瑮眭楥桧㩴渠牯慭㭬氠瑥整⵲灳捡湩㩧渠牯慭㭬氠湩ⵥ敨杩瑨›潮浲污※牯桰湡㩳㈠※整瑸愭楬湧›畡潴※整瑸椭摮湥㩴〠硰※整瑸琭慲獮潦浲›潮敮※桷瑩ⵥ灳捡㩥渠牯慭㭬眠摩睯㩳㈠※潷摲猭慰楣杮›瀰㭸ⴠ敷止瑩戭牯敤⵲潨楲潺瑮污猭慰楣杮›瀰㭸ⴠ敷止瑩戭牯敤⵲敶瑲捩污猭慰楣杮›瀰㭸ⴠ敷止瑩琭硥⵴敤潣慲楴湯⵳湩攭晦捥㩴渠湯㭥ⴠ敷止瑩琭硥⵴楳敺愭橤獵㩴愠瑵㭯ⴠ敷止瑩琭硥⵴瑳潲敫眭摩桴›瀰㭸映湯⵴楳敺›敭楤浵※㸢猼慰汣獡㵳䄢灰敬猭祴敬猭慰≮猠祴敬∽潦瑮昭浡汩㩹嘠牥慤慮‬牁慩ⱬ䠠汥敶楴慣‬慳獮猭牥晩※潦瑮猭穩㩥ㄠ瀲㭸氠湩ⵥ敨杩瑨›㠱硰※㸢戼㹲桔⁥楦獲⁴睴敭獳条⁥潢數⁳牡⁥汢湡湡⁤桴⁥爳⁤慨⁳楧扢牥獩⁨桷湥䤠挠灯⁹⁡潷摲搠捯浵湥⁴牯樠獵⁴汢湡桷湥挠灯楹杮映潲⁡整瑸搠捯浵湥⹴⼼灳湡㰾猯慰㹮਍ℼⴭ湅䙤慲浧湥⵴㸭਍⼼潢祤ാ㰊栯浴㹬
---------------------------
OK   
---------------------------


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Which version of AutoHotkey are you using?

Edit:

Okay! You are using Unicode...
I can rewrite it if you can allow me one day.

beetle120
  • Members
  • 4 posts
  • Last active: Oct 20 2010 05:28 AM
  • Joined: 20 Oct 2010

Which version of AutoHotkey are you using?


Version v1.0.48.05.L61 I just downloaded it not long ago

Edit:

Okay! You are using Unicode...
I can rewrite it if you can allow me one day.


I would love that. Thank You so much :D

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
ClipboardGet_HTML( byref Data ) { ; www.autohotkey.com/forum/viewtopic.php?p=392624#392624
 If CBID := DllCall( "RegisterClipboardFormat", Str,"HTML Format", UInt )
  If DllCall( "IsClipboardFormatAvailable", UInt,CBID ) <> 0
   If DllCall( "OpenClipboard", UInt,0 ) <> 0
    If hData := DllCall( "GetClipboardData", UInt,CBID, UInt )
       DataL := DllCall( "GlobalSize", UInt,hData, UInt )
     , pData := DllCall( "GlobalLock", UInt,hData, UInt )
     , VarSetCapacity( data, dataL * ( A_IsUnicode ? 2 : 1 ) ), StrGet := "StrGet"
     , A_IsUnicode ? Data := %StrGet%( pData, dataL, 0 )
                   : DllCall( "lstrcpyn", Str,Data, UInt,pData, UInt,DataL )
     , DllCall( "GlobalUnlock", UInt,hData )
 DllCall( "CloseClipboard" )
Return dataL ? dataL : 0
}

If ClipboardGet_HTML( Data )
     MsgBox, % Data
Else SoundBeep

kWo4Lk1.png

beetle120
  • Members
  • 4 posts
  • Last active: Oct 20 2010 05:28 AM
  • Joined: 20 Oct 2010
It works perfectly. Thank you so much. :D