http://www.perlmonks.org?node_id=888927

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

Replies are listed 'Best First'.
Re: WIn32::OLE Excel Bold a Word and Wrap Text
by cormanaz (Deacon) 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 (Deacon) 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.