import pandas as pd
import openpyxl
from openpyxl import Workbook, load_workbook
from openpyxl.styles import Color, PatternFill, Font, Border
from openpyxl.styles.borders import Border, Side, BORDER_THIN
from openpyxl.styles import colors
from openpyxl.cell import Cell
import io
openpyxl.__version__
#https://stackoverflow.com/questions/30484220/fill-cells-with-colors-using-openpyxl
#https://stackoverflow.com/questions/24917201/applying-borders-to-a-cell-in-openpyxl
df = pd.DataFrame([[1,2,3], [4,5,6]])
df.columns = ['a', 'b', 'c']
df.head()
output = io.BytesIO()
df.to_excel(output, index=False)
workbook = load_workbook(output)
s = workbook['Sheet1']
#styles
whitehex = 'ffffff'
fontWhite = Font(color=whitehex)
darkBlue = PatternFill(start_color='305496', end_color='305496', fill_type='solid')
lightBlue = PatternFill(start_color='e9ebf5', end_color='e9fbf5', fill_type='solid')
border = Border(
left=Side(border_style=BORDER_THIN, color=whitehex),
right=Side(border_style=BORDER_THIN, color=whitehex),
top=Side(border_style=BORDER_THIN, color=whitehex),
bottom=Side(border_style=BORDER_THIN, color=whitehex)
)
for idx, row in enumerate(s.iter_rows()):
for cell in row:
if idx == 0:
cell.fill = darkBlue
cell.font = fontWhite
else:
cell.fill = lightBlue
cell.border = border
print(idx, row)
workbook.save("test.xlsx")
from IPython.display import display
from PIL import Image
display(Image.open('./image.png'))