[英]How to copy from Excel and paste as image in Word using Python?
How do I copy a set of cells from Excel and paste them as image in Word using Python ? 如何使用Excel复制一组单元格并将其粘贴为Word中的图像?
I am trying to automate some reports (in docx format). 我正在尝试自动化一些报告(docx格式)。 The excels are auto generated and then I have to manually copy cells from Excel and paste as image in Word. excel是自动生成的,然后我必须手动从Excel复制单元格并将其粘贴为Word中的图像。
I have done some research and found there are some libraries like python-docx (for word) and openpyxl (for excel). 我进行了一些研究,发现有一些库,例如python-docx(用于word)和openpyxl(用于excel)。 What I am not able to figure out is the copy and paste as image from excel to word. 我不知道是从excel到Word的复制和粘贴图像。
I don't think this is an easy task. 我认为这不是一件容易的事。 Because conversion Excel to image probably means the Python package/codes need to know how to render the excel content, which is a big step beyond read/write excel format. 由于将Excel转换为图像可能意味着Python程序包/代码需要知道如何呈现excel内容,这是读写excel格式之外的一大步。 I don't know any Python package can do that. 我不知道任何Python包都能做到这一点。
Assume you're running Python codes in Windows, you may try to call COM to copy/paste directly from Excel to Word. 假设您在Windows中运行Python代码,则可以尝试调用COM将Excel直接复制/粘贴到Word。 I guess that would behave just like you manually Ctrl+C/V. 我想那会像您手动按Ctrl + C / V一样。 Reference 参考
If you prefer to convert to an image, may try a VBA script. 如果您希望转换为图像,可以尝试使用VBA脚本。 Reference 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.