Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
laziness, impatience, and hubris
 
PerlMonks  

WIn32::OLE Excel Bold a Word and Wrap Text

by cormanaz (Chaplain)
on Feb 18, 2011 at 15:34 UTC ( #888927=perlquestion: print w/ replies, xml ) Need Help??
cormanaz has asked for the wisdom of the Perl Monks concerning the following question:

Howdy Bros. I'm trying to do two things in Excel 2010 using Win32::OLE and can't find the answer as to how.

1. How do I set the properties of a cell to wrap the text it contains? This would be the equivalent in the Excel UI of right clicking a cell and selecting Format Cells, Alignment tab, check Wrap Text. I tried $Sheet->Range("A1")->{'Alignment'}->{'WrapText'} = "True"; but that throws an error.

2. How do I boldface a single word in a range? I know you can bold a whole cell with $sheet -> Range("A1") -> Font -> {Bold} = "True"; but how do you do it for a single word in a cell?

TIA...

Steve

Comment on WIn32::OLE Excel Bold a Word and Wrap Text
Select or Download Code
Re: WIn32::OLE Excel Bold a Word and Wrap Text
by cormanaz (Chaplain) on Feb 18, 2011 at 16:34 UTC
    After about 45 min of hunting through Microsoft's byzantine docs system, I found the object reference for Excel 2010. That gives the answer to question 1: $Sheet->Range("A1")->{'WrapText'} = "True"; (I was close).

    But it's no help on question 2. It must have something to do with the value property of the range object, but the docs give no indication of how you reference something within the value.

      cormanaz:

      I seem to recall that you need to select the word, and then apply the bold to the selection. Hopefully that'll give you a clue where to look in the documentation.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

Re: WIn32::OLE Excel Bold a Word and Wrap Text
by Gulliver (Monk) on Feb 18, 2011 at 20:05 UTC
Re: WIn32::OLE Excel Bold a Word and Wrap Text
by cormanaz (Chaplain) on Feb 18, 2011 at 22:57 UTC
    Thanks for the suggestions. Use the macro recorder--why didn't I think of that?

    The answer to question 2 is $Sheet->Range("a1")->Characters(5,5)->{'Font'}->{'Bold'} = 'True'; (assuming the word starts at char 5 and is 5 chars long). Bear in mind that the char numbering starts at 1, not 0.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://888927]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2014-04-21 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (495 votes), past polls