Jump to content

Clipboard to HTML ?


 Share

Recommended Posts

Since Word seems to add HTML to its Clipboard output formats, maybe _ClipGetHTML might help out? ;)

Link to comment
Share on other sites

This example is working on my XP and using MS Word 2002.

To use this script, either pre-copy, or, highlight the data to be put into the htm file before you press the "F2" key.

#include <Word.au3>

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F2}", "ClipBrdToHtm") ; Press F2

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

While 1
    Sleep(20)
WEnd

; Highlight part or all of a Word Doc file from within MS Word; or
; Have the clipboard pre-copied with nothing highlighted; or
; Use SciTE instead of MS Word.
; Then, press the F2 key when this script is running.
; The text with format, image and/or table that was copied will be put into "Temp.htm" file.
Func ClipBrdToHtm()
    Send("^c") ; Copy highlighted text
    If ClipGet() <> "" Then
        Local $sFileName = @ScriptDir & "\Temp.htm"

        $oWordApp = _WordCreate()
        $oDoc = _WordDocGetCollection($oWordApp, 0)
        _WordDocSaveAs($oDoc, $sFileName, 10) ; Doc file saved in filtered HTML format.

        WinActivate("Temp.htm")
        WinWaitActive("Temp.htm")
        Send("^v") ; Paste
        _WordDocSave($oDoc)
        ;_WordQuit($oWordApp) ; Uncomment for personal preference - use or not?

        ; For demonstrational purposes only.
        ShellExecute($sFileName) ; Will open file with application associated with file extension (.htm)
        Sleep(2000)
        FileDelete($sFileName); Clean up file for this example.
    EndIf
EndFunc ;==>ClipBrbToHtm

Func Terminate()
    Exit 0
EndFunc ;==>Terminate
Link to comment
Share on other sites

This example is working on my XP and using MS Word 2002.

To use this script, either pre-copy, or, highlight the data to be put into the htm file before you press the "F2" key.

#include <Word.au3>

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F2}", "ClipBrdToHtm") ; Press F2

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

While 1
    Sleep(20)
WEnd

; Highlight part or all of a Word Doc file from within MS Word; or
; Have the clipboard pre-copied with nothing highlighted; or
; Use SciTE instead of MS Word.
; Then, press the F2 key when this script is running.
; The text with format, image and/or table that was copied will be put into "Temp.htm" file.
Func ClipBrdToHtm()
    Send("^c") ; Copy highlighted text
    If ClipGet() <> "" Then
        Local $sFileName = @ScriptDir & "\Temp.htm"

        $oWordApp = _WordCreate()
        $oDoc = _WordDocGetCollection($oWordApp, 0)
        _WordDocSaveAs($oDoc, $sFileName, 10) ; Doc file saved in filtered HTML format.

        WinActivate("Temp.htm")
        WinWaitActive("Temp.htm")
        Send("^v") ; Paste
        _WordDocSave($oDoc)
        ;_WordQuit($oWordApp) ; Uncomment for personal preference - use or not?

        ; For demonstrational purposes only.
        ShellExecute($sFileName) ; Will open file with application associated with file extension (.htm)
        Sleep(2000)
        FileDelete($sFileName); Clean up file for this example.
    EndIf
EndFunc ;==>ClipBrbToHtm

Func Terminate()
    Exit 0
EndFunc ;==>Terminate

That is nice too!

Link to comment
Share on other sites

Something like this.

ClipPut(StringRegExpReplace(ClipGet(), "[^[:lower:]]", ""))
; or
ClipPut(StringReplace(ClipGet(), "this", "THIS"))

no-no-no. Clipboard consists of data, that we copyed from MS Word. It is not raw(plain) text, but formatted text with tables, styles, etc.

And I have to do replaces with regular expressions in this text (because MS Word does not support RCRE).

If we just do what you've written, all tables and styles will dissapper.

Edited by Suppir
Link to comment
Share on other sites

If _ClipGetHtml() returns an array, you can do all the StringRegExpReplace/StringReplace's you want.

For example:

$aHTML=_ClipGetHTML()
If @error Then Exit
$sHTML=StringRegExpReplace($aHTML[0],"replace(this)","that")
FileWrite(@DesktopDir&"\test.html",$sHTML)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...