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

In reply to Perl & Word (OLE objects query not exactly on perl) by barathbr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.