Python 使用use_iterators=True在OpenPyxl中格式化
这与我前面的问题类似。唯一的区别是,现在我真的想使用优化的工作簿来提高速度 基本上,当我使用优化的阅读器时,我不知道如何检索格式细节。这是一个玩具样本,这些评论解释了我在打印报表上看到的内容。我做错什么了吗?是否有更好的方法检索格式详细信息 另外,如果有人知道另一个excel reader for python支持xlsx+检索格式,我很乐意更改!(我已经尝试过xlrd,虽然它在较新版本中支持xlsx,但它还不支持格式化)Python 使用use_iterators=True在OpenPyxl中格式化,python,openpyxl,Python,Openpyxl,这与我前面的问题类似。唯一的区别是,现在我真的想使用优化的工作簿来提高速度 基本上,当我使用优化的阅读器时,我不知道如何检索格式细节。这是一个玩具样本,这些评论解释了我在打印报表上看到的内容。我做错什么了吗?是否有更好的方法检索格式详细信息 另外,如果有人知道另一个excel reader for python支持xlsx+检索格式,我很乐意更改!(我已经尝试过xlrd,虽然它在较新版本中支持xlsx,但它还不支持格式化) 样式ID似乎是在工作簿->共享样式(book.shared\u样式或sh
样式ID似乎是在工作簿->共享样式(book.shared\u样式或sheet.parent.shared\u样式)中查找样式信息的索引 在一些工作手册中,这是完美的;但是,我在其他工作簿中也发现,样式ID大于共享样式的长度,因此当我尝试访问这些样式时,会出现“超出范围”的异常
from openpyxl import Workbook
from openpyxl.reader.excel import load_workbook
from openpyxl.style import Color, Fill
#this is all setup
wb = Workbook()
dest_filename = 'c:\\temp\\test.xlsx'
ws = wb.worksheets[0]
ws.title = 'test'
ws.cell('A1').value = 'foo'
ws.cell('A1').style.font.bold = True
ws.cell('B1').value = 'bar'
ws.cell('B1').style.fill.fill_type = Fill.FILL_SOLID
ws.cell('B1').style.fill.start_color.index = Color.YELLOW
wb.save(filename = dest_filename )
#setup complete
book = load_workbook( filename = dest_filename, use_iterators = True )
sheet = book.get_sheet_by_name('test')
for row in sheet.iter_rows():
for cell in row:
print cell.coordinate
print cell.internal_value
print cell.style_id #returns different numbers here (1, and 2 in case anyone is interested)
print sheet.get_style(cell.coordinate).font.bold #returns False for both
print sheet.get_style(cell.coordinate).fill.fill_type #returns none for bothe
print sheet.get_style(cell.coordinate).fill.start_color.index #returns FFFFFFFF (white I believe) for both
print
import openpyxl
print openpyxl.__version__ #returns 1.6.2