Suppir Posted August 15, 2010 Share Posted August 15, 2010 Hello! I have some text copyed from MS Word in clipboard. Is the any way to get HTML file from this text? (maybe some UDF exists?) Link to comment Share on other sites More sharing options...
Ascend4nt Posted August 15, 2010 Share Posted August 15, 2010 Since Word seems to add HTML to its Clipboard output formats, maybe _ClipGetHTML might help out? My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Suppir Posted August 15, 2010 Author Share Posted August 15, 2010 Ascend4nt, wow! That is realy good, thanks! Link to comment Share on other sites More sharing options...
Malkey Posted August 15, 2010 Share Posted August 15, 2010 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. expandcollapse popup#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 More sharing options...
Suppir Posted August 15, 2010 Author Share Posted August 15, 2010 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. expandcollapse popup#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 More sharing options...
Suppir Posted August 15, 2010 Author Share Posted August 15, 2010 Is it possible to do some replaces in clipboard before generating HTML?Replaces with regular expressions. Link to comment Share on other sites More sharing options...
Malkey Posted August 15, 2010 Share Posted August 15, 2010 Something like this. ClipPut(StringRegExpReplace(ClipGet(), "[^[:lower:]]", "")) ; or ClipPut(StringReplace(ClipGet(), "this", "THIS")) Link to comment Share on other sites More sharing options...
Suppir Posted August 15, 2010 Author Share Posted August 15, 2010 (edited) 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 August 15, 2010 by Suppir Link to comment Share on other sites More sharing options...
Ascend4nt Posted August 15, 2010 Share Posted August 15, 2010 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) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
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