繁体   English   中英

如何使用 python 在 Excel 单元格中显示嵌入的文本文件

[英]How to display embedded text file in Excel cell using python

我在Excel单元格中嵌入了文本(文档)文件,但它显示为一个big icon ,占用太多空间。 如何将图标更改为适合单元格的超链接相似名称?

我有一个Excel文件text.xlsx 我在单元格B3中嵌入了文件profile.docx 以下代码可以做到这一点 -

import win32com.client as win32
sourceFile = r'E:\test.xlsx'
fileToEmbed = r'E:\profile.docx'
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(sourceFile)
ws = wb.Worksheets("Tabelle1")
dest_cell = ws.Range("B3") #change to your wanted location
obj = ws.OLEObjects()
wordpath = 'C\\Program Files (x86)\\Microsoft Office\\Office 14\\WINWORD.EXE'
obj.Add(ClassType=None,Filename=fileToEmbed,Link=False,DisplayAsIcon=True, IconFileName=wordpath,IconIndex=0,IconLabel='Profile.docx',Left=dest_cell.Left, Top=dest_cell.Top,Width=1,Height=1)
wb.Save()
excel.Application.Quit()

左边是我得到的,右边是我想要的。

在此处输入图像描述

您是如何在右侧图片上手动添加文件的? 它看起来像超链接,而不是嵌入文件。 手动使用嵌入(通过 Excel GUI)我根本无法让它看起来像那样。 所以你问的可能是不可能的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM