How do I select only part of a row in an excel cell using python

I am using win32com to populate an Excel spreadsheet with some analytic information. I have a cell in which I want to be in this form:

This is a description of the problem: this is the command that you run to fix it

I can't figure out how to get text into a cell using python with mixed formatting.

import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Add()
ws = wb.Worksheets("Sheet1")
excel.Visible=True
sel = excel.Selection
sel.Value = "this is the command you run to fix it"
sel.Font.Bold = True
ws.Cells(1,1).Value = 'This is the problem description' + sel.Value  #makes the whole cell bold
ws.Cells(1,1).Value = "{} {}".format("this is the problem desc",sel) #makes the whole cell bold

The select object has an Characters attribute, but I cannot find documentation about what it does. I'm losing a little here, I could use help.

thank

+4
source share
2 answers

- , , .

Per @ron-rosenfield, VBA, , :

Range("A1").Characters(2,5).Font.Bold = true 

, Characters excel WorkSheet

>>> ws.Range("A1").Characters
<win32com.gen_py.Microsoft Excel 14.0 Object Library.Characters 967192>

HOWEVER, , , GetCharacters (, ) ( 1, , excel com)

ws.Range("A1").GetCharacters(2,4).Font.Bold = True

.

+4

, win32com , , , Python XlsxWriter.

Example:

enter image description here

+1

All Articles