【发布时间】:2014-10-21 14:36:53
【问题描述】:
我正在使用 win32com 填写包含一些分析信息的 Excel 电子表格。我有一个单元格,我想采用这种形式:
这是问题描述:这是您运行修复它的命令
我似乎不知道如何使用混合格式将文本放入单元格中。
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Add()
ws = wb.Worksheets("Sheet1")
excel.Visible=True
sel = excel.Selection
sel.Value = "this is the command you run to fix it"
sel.Font.Bold = True
ws.Cells(1,1).Value = 'This is the problem description' + sel.Value #makes the whole cell bold
ws.Cells(1,1).Value = "{} {}".format("this is the problem desc",sel) #makes the whole cell bold
选择对象有一个 Characters 属性,但我找不到任何关于它的作用的文档。
【问题讨论】:
-
我什至不知道 Excel 能够像这样的混合格式...
-
嗯。以前没有。
-
@DerekChadwell,您使用的是哪个 excel 版本?
-
Office 2010 套件的一部分:版本 14.0.6123.5001(32 位)
标签: python excel formatting win32com