これは、openpyxl でフォーマット データを取得する以前の質問に似ています 。唯一の本当の違いは、速度を上げるために最適化されたワークブックを本当に使用したいということです。
基本的に、最適化されたリーダーを使用すると、フォーマットの詳細を取得する方法がわかりません。これはおもちゃのサンプルです。コメントは、印刷ステートメントで見ていることを説明しています。私は何か間違ったことをしていますか?フォーマットの詳細を取得するより良い方法はありますか?
また、誰かが xlsx + フォーマットの取得をサポートする Python 用の別の Excel リーダーを知っていれば、私は変更を受け入れます! (私はすでにxlrdを試しましたが、新しいビルドではxlsxをサポートしていますが、フォーマットはまだサポートしていません)
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