简体   繁体   中英

Format an Excel Sheet in Python

I am importing data from various web queries into a Jupyter Notebook and cleaning it in there and creating various forecasts etc.

The end output is required in an Excel file. However, the Excel file I create is simply a table of data and not very user-friendly.

One request I have from a user is to have the rows in the excel sheet in one color for weekends and another color for weekdays (the data is all datetime data).

Is there anyway of automatic the formatting of the excel sheet in python so that the whole process of creating the sheet is automated?

eg; First row of headers would be bold All rows representing weekend would be a one color. etc

At present I'm using the xlsxwriter

writer = pd.ExcelWriter('Americas.xlsx', engine='xlsxwriter') 
df.to_excel(writer, sheet_name='WestFacilities') 

Any help much appreciated!

The below code will help you refer here https://xlsxwriter.readthedocs.io/format.html

cell_format = workbook.add_format({'bold': True, 'font_color': 'red'})
worksheet.write('A1', 'Cell A1', cell_format)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM