Format Excel output - Python

4

I transform a list into a Dataframe and send it to an Excel, it's working fine. Here is the code:

Df = pd.DataFrame(Lista, columns = colunas_geradas)

writer = pd.ExcelWriter('Exemplo.xlsx', engine = 'xlsxwriter')
Df.to_excel(writer, sheet_name = 'Teste', index = False)
writer.save()

I wonder if you can format Excel in code. For example: Changing the color of the Column Names, arranging the size of the ballots, adding an image, things like that.

    
asked by anonymous 17.05.2017 / 16:55

1 answer

0

The pandas library has a guide on how to work with styles , but warn that it is a new functionality, implemented from version 0.17.1.

In this link I have provided you with code snippets to paint, create graphics, change colors of cell contents, etc.

Change the color of column names: I do not think it's possible.

Size the cells: I do not think so, however, I found #

In addition to the pandas library, I know of two other libraries that allow you to manipulate spreadsheets:

And the openpyxl library, which also has a topic just to talk about how to work with pandas and a topic to teach a little about how to work with styles .

In addition to these libraries, I leave this link that I found extremely informative: Improving Pandas Excel Output .

    
23.05.2017 / 05:24