简体   繁体   中英

Python - win32 - Underline

I want to format some cells. I can select bold or italic with the following code:

import win32com.client as win32

wb = excel.Workbooks.Open(template_file)
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(template_file)

wb.Worksheets(sheet).Range(range_selected).Font.Bold = 'True'
wb.Worksheets(sheet).Range(range_selected).Font.Italic = 'True'

But when I try to select underline it doesn't work. I have tried the following options:

wb.Worksheets(sheet).Range(range_selected).Font.Italic = 'True'
wb.Worksheets(sheet).Range(range_selected).Font.Underline = "xlUnderlineStyleSingle"  -- from VBA

Could anyone help?

Thanks,

Julen

You can try the numerical values

Name Value Description
xlUnderlineStyleDouble -4119 Double thick underline.
xlUnderlineStyleDoubleAccounting 5 Two thin underlines placed close together.
xlUnderlineStyleNone -4142 No underlining.
xlUnderlineStyleSingle 2 Single underlining.
xlUnderlineStyleSingleAccounting 4 Not supported.

Eg,

wb.Worksheets(sheet).Range(range_selected).Font.Underline = 2

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