Formatting cells in Excel using Python

How to format cells in Excel using python?

In particular, I need to change the font of the next few lines to be regular, not bold.

+6
source share
4 answers

Using xlwt :

from xlwt import * font0 = Font() font0.bold = False style0 = XFStyle() style0.font = font0 wb = Workbook() ws0 = wb.add_sheet('0') ws0.write(0, 0, 'myNormalText', style0) font1 = Font() font1.bold = True style1 = XFStyle() style1.font = font1 ws0.write(0, 1, 'myBoldText', style1) wb.save('format.xls') 
+3
source

To use Python operations for Excel, I highly recommend checking out this site . There are three python modules that let you do almost everything you need: xlrd (read), xlwt (write) and xlutils (copy / modify / filter). The site I mentioned has a lot of information related to documentation and examples. In particular, you might be interested in this example . Good luck

+3
source

For general examples of Excel scripts from Python, this snippet is very convenient. This does not mean that "change the font to normal", but it is simply range.Font.Bold = False in the function, otherwise it is very similar to set_border in this fragment.

+1
source

The following is a brief introduction to using xlwt and optional xlrd (for reading .xls files). However, the Reddit thread , where I found that the article contains a huge amount of useful tips, including some warnings and ways to use win32com to better write Excel files (see this comment ) - frankly, I find the code easier to read /support. You will probably learn a lot more about this rather active python-excel group.

+1
source

Source: https://habr.com/ru/post/1286597/


All Articles