How can I copy from an html file to the clipboard in Python in formatted text?

被刻印的时光 ゝ 提交于 2019-11-27 07:50:43

问题


I'm writting a Word document and I'd like to paste a formatted code-snippets directly from clipboard.

At this moment I am able to write these snippets into an .html file to the harddisk. My goal is to extend my Python script and load this .html file on the clipboard in "formatted text" to directly paste at Word.

Does anyone knows any way to do this in Python?

Thanks in advance.

Sherab


回答1:


Well, I've found a solution for this.

http://code.activestate.com/recipes/474121-getting-html-from-the-windows-clipboard/

It's work pretty well... if anyone wants more information about the clipboard just take a look here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms649013(v=vs.85).aspx

Download the pywin32 module and with win32clipboard you can do everything.




回答2:


I used com interface to do it. http://en.wikipedia.org/wiki/Component_Object_Model

The simpliest way: - create word template in microsoft word. - paste text from code in your template.



来源:https://stackoverflow.com/questions/17298897/how-can-i-copy-from-an-html-file-to-the-clipboard-in-python-in-formatted-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!