简体   繁体   English

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

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

I have embedded text (document) file into Excel cell, but it's displayed as a big icon , which occupies too much space.我在Excel单元格中嵌入了文本(文档)文件,但它显示为一个big icon ,占用太多空间。 How can I change icon into a hyperlink lookalike name fitting the cell?如何将图标更改为适合单元格的超链接相似名称?

I have an Excel file text.xlsx .我有一个Excel文件text.xlsx I have embedded a file profile.docx in cell B3 .我在单元格B3中嵌入了文件profile.docx The following code does that -以下代码可以做到这一点 -

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()

On the left hand side is what I get, and on right hand side is what I want.左边是我得到的,右边是我想要的。

在此处输入图像描述

How did you add the file manually on the right picture?您是如何在右侧图片上手动添加文件的? It looks like a Hyperlink, not an embedded file.它看起来像超链接,而不是嵌入文件。 Using embedding manually (through the Excel GUI) I cannot get it to look like that at all.手动使用嵌入(通过 Excel GUI)我根本无法让它看起来像那样。 So what you are asking might be impossible.所以你问的可能是不可能的。

暂无
暂无

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

相关问题 使用python将文本文件(对象)作为.txt插入到Excel工作表的单元格中 - Insert a text file (object) as .txt into a cell of excel sheet using python 在 Excel 文件中,如何使用 openpyxl (Python) 查找单元格的背景颜色 - In a Excel file how to find the background color of a cell using openpyxl (Python) 我想使用 python 在特定单元格上的现有 excel 文件中放置一个文本文件 - I would like to put a text file in existing excel file on specific cell using python 如何使用python将excel文件的所有行和列组合到另一个excel文件的单个单元格中? - How to combine all rows and columns of an excel file into a single cell of another excel file using python? 我们可以使用 python 解析.txt 文件并将多行解析文本复制到 excel 单元格吗? - Can we parse .txt file and copy multiline parsed text to excel cell using python? 如何使用python openpyxl将文本文件的特定部分复制到excel工作表中的特定单元格? - How to copy a specific portion of text file to a specific cell in excel worksheet with python openpyxl? 如何使用 python 循环读取 excel 中的单元格? - How to read a cell in excel using a python for loop? 使用python将文本添加到现有excel文件的特定列的每个单元格中 - Add text to each cell of a particular column of an existing excel file with python 如何避免使用python覆盖excel中的单元格? - How to avoid overwriting of cell in excel using python? 如何使用Python提取Excel单元格的值? - How to extract the value of an excel cell using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM