xl_range
to specify the cell. (Specify the cell numerically)The entire
# xl_If you use range,"B2:C3"Xl_range(2,2,3,3)Can be expressed as.
from xlsxwriter.utility import xl_range
import xlsxwriter
import pandas as pd
import numpy as np
#Data frame for test
df = pd.DataFrame(np.arange(0,9,1).reshape(3,3))
#workbook generation
workbook = xlsxwriter.Workbook(r'./output_storage/hoge.xlsx')
#In xlsxwriter, mode='a'Cannot be used.
writer = pd.ExcelWriter(r'./output_storage/hoge.xlsx',mode='w',engine='xlsxwriter')
sheet_name = 'hoge'
#Write a data frame to a sheet
df.to_excel(writer,sheet_name=sheet_name,startrow=0,index_label='huga')
#Conditional formatting
ws = writer.sheets[sheet_name]
ws.conditional_format(xl_range(2,2,3,3),
{'type': '3_color_scale',
'min_color': "#44c242",
'mid_color': "#ebeb44",
'max_color': "#eb4444"})
writer.close()
Recommended Posts