barathbr has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, I have a query on working with Word using Win32::OLE. The problem I am running into is more of a OLE question than a Perl question I suppose. But I couldn't think of a better resource, so...

I am working with some Excel documents which I am converting to word. I open an excel object and pull out the specific values which I need and everything functions like it supposed to. I am able to parse and print data to a text file.

The problem occurs when I try to set multiple fonts on a single line.

I have a create style sub:
sub create_style { my $document = shift; my $fontname = shift; my $font_size = shift; my $bold = shift; my $italic = shift; my $style = $document->Styles->Add($cur_style); my $style_font = $style->{Font}; $style_font -> {Name } = $fontname; $style_font -> {Size } = $font_size; $style_font -> {Bold } = $bold; $style_font -> {Italic} = $italic; my %style; $style{name} = $cur_style++; return \%style; }
set style sub:
sub set_style { my $document = shift; my $style_arg = shift; $document->ActiveWindow->Selection -> {Style} = $style_arg -> {name} +; }
create style with:
my $st_normal_10_trebuchetMS = create_style($document, "Trebuchet MS +", 10, 0, 0); my $st_italic_10_trebuchetMS = create_style($document, "Trebuchet MS +", 10, 0, 1);
I set the actual font like so:
elsif ($col == 10) { set_style($document, $st_bold_10_trebuchetMS); text ($document, "ER: "); set_style($document, $st_normal_10_trebuchetMS); text ($document, "$value"); }
But during execution, it sets "ER:" to bold and immediately afterwards when I throw in the other style arg, it converts "ER:" also to NOT bold.

I think that it is because of these two that it is misbehaving:
my $document = $Word->Documents->Add; my $selection = $Word->Selection;
I "think" the context is a global one dont know for sure. And I dont know exactly what to fix. Pl. note that this is the first time I am playing with OLE objects and perl.

Thanks to the Perl Excel tutorial node that is already there on perlmonks, I didn't run into any issues while parsing the excel sheet. But handling word appears to be a little more complicated. Any help, links, pointers, anything at all ???

Thanks in advance

Replies are listed 'Best First'.
Re: Perl & Word (OLE objects query not exactly on perl)
by PodMaster (Abbot) on Feb 01, 2005 at 11:56 UTC
    So you're saying that "ER:" is still selected the second time you change the font? It sounds you need to find out what constitutes a Selection.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Yes it is a problem with what a selection constitutes. I wasn't sure what it is, so I thought somebody else might have already worked with it before and hence the question.
        I wasn't sure what it is, so I thought somebody else might have already worked with it before and hence the question.
        I'm sure the developers who wrote the method documented it someplace. Can you guess where?

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.