Created
July 1, 2014 05:44
-
-
Save oyakata/824dad8fa3eb4d729790 to your computer and use it in GitHub Desktop.
openpyxlの使い方(背景色と罫線をつける)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import openpyxl as ox | |
# インポートはもっときれいな方法があるかも | |
from openpyxl.styles.fills import FILL_SOLID | |
from openpyxl.styles.colors import Color, RED, BLUE | |
from openpyxl.styles.fills import PatternFill | |
from openpyxl.styles.borders import Border, Side as BorderSide, BORDER_THIN | |
# ソースコードはBitbucketにあるので注意。Githubではない。 | |
# openpyxl==2.0.4 | |
# https://bitbucket.org/ericgazoni/openpyxl/src/f6e73078b66d/openpyxl/?at=default | |
book = ox.Workbook() | |
sheet = book.active | |
sheet.title = u"お-と-し-ま-え" | |
sheet.cell("A1").value = u"滝川" | |
cell = sheet.range("C8") | |
cell.value = u"ここが色と罫線がつくよ!!!" | |
cell.style = cell.style.copy( | |
fill=PatternFill( | |
start_color=Color(RED), | |
end_color=Color(RED), | |
fill_type=FILL_SOLID, | |
), | |
border=cell.style.border.copy( | |
left=BorderSide(color=Color(BLUE), style=BORDER_THIN), | |
right=BorderSide(color=Color(BLUE), style=BORDER_THIN), | |
top=BorderSide(color=Color(BLUE), style=BORDER_THIN), | |
bottom=BorderSide(color=Color(BLUE), style=BORDER_THIN), | |
), | |
) | |
book.save(filename="hey.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's not work,
TypeError: copy() got an unexpected keyword argument 'fill'