Win32::OLE and Bulleted Lists

Discussion in 'Perl Misc' started by jr, Feb 6, 2006.

  1. jr

    jr Guest

    Hi. I'm trying to bullet a row of text, using Win32::OLE. A module
    called "Win32::Word::Writer" seems to do just what I want, but I'm not
    able to install it, through either CPAN or PPM. I'm therefore hoping
    it is possible to do using only Win32::OLE. I've searched for days,
    and the only suggestion I've been able to find is to record a macro in
    Word, then port that macro over to Perl. I've tried that, with no luck
    (I have zero experience in porting macros). I've also tried recording
    a macro, where I bullet a row, and then and looking at the VB code.
    This hasn't been helpful either. Is this even possible using only
    Win32::OLE? If so, I'd really appreciate an example. This is making
    me want to pull out what's left of my hair.

    Below is a simple example of the code I found online for creating a
    Word document. There must be an easy way, using some method I can't
    find anywhere, for bulleting one of the text lines...hopefully, at
    least!

    Thanks!


    ####### HelloWord.pl
    use warnings;
    use strict;

    use Win32::OLE;

    my $word = CreateObject Win32::OLE 'Word.Application' or die $!;
    $word->{'Visible'} = 1;

    my $document = $word->Documents->Add;

    my $selection = $word->Selection;

    $selection ->TypeText("Hello World");
    $selection ->TypeParagraph;
    $selection ->TypeText("How do you feel today");
    $selection ->TypeParagraph;

    $selection ->TypeText("Some header");
    $selection ->{'Style'} = "Heading 1";

    $selection ->TypeParagraph;

    my $heading_1 = $document->Styles("Heading 1");
    my $heading_1_font = $heading_1 -> Font;

    $heading_1_font -> {Name} = "Bookmann";
    $heading_1_font -> {Size} = 20;
    $heading_1_font -> {Bold} = 1;
    jr, Feb 6, 2006
    #1
    1. Advertising

  2. "jr" <> wrote in
    news::

    > Hi. I'm trying to bullet a row of text, using Win32::OLE. A module
    > called "Win32::Word::Writer" seems to do just what I want,


    I haven't used that module so I cannot comment on it.

    > Is this even possible using only Win32::OLE?


    Yes. The way to figure this out is to record the simplest possible
    macro, then look at it in the VBA editor. The VBA editor has an "Object
    Browser" that is accessible via F2. Looking at classes, methods, and
    properties in the object browser also helps.

    #!/usr/bin/perl

    use strict;
    use warnings;

    use Win32::OLE;
    use Win32::OLE::Const 'Microsoft Word';

    $Win32::OLE::Warn = 3;

    my $word;
    eval {
    $word = Win32::OLE->GetActiveObject('Word.Application');
    };

    die "$@\n" if $@;

    unless(defined $word) {
    $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit })
    or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n";
    }

    $word->{Visible} = 1;
    my $doc = $word->Documents->Add;

    my $selection = $word->Selection;
    $selection->Range->ListFormat->ApplyBulletDefault;
    $selection->TypeText("Hello World");
    $selection->TypeParagraph;
    $selection->TypeText("How do you feel today");
    $selection->TypeParagraph;


    sleep 10;


    __END__


    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 6, 2006
    #2
    1. Advertising

  3. jr

    jr Guest

    A. Sinan Unur wrote:
    > "jr" <> wrote in
    > news::
    >
    > > Hi. I'm trying to bullet a row of text, using Win32::OLE. A module
    > > called "Win32::Word::Writer" seems to do just what I want,

    >
    > I haven't used that module so I cannot comment on it.
    >
    > > Is this even possible using only Win32::OLE?

    >
    > Yes. The way to figure this out is to record the simplest possible
    > macro, then look at it in the VBA editor. The VBA editor has an "Object
    > Browser" that is accessible via F2. Looking at classes, methods, and
    > properties in the object browser also helps.
    >
    > #!/usr/bin/perl
    >
    > use strict;
    > use warnings;
    >
    > use Win32::OLE;
    > use Win32::OLE::Const 'Microsoft Word';
    >
    > $Win32::OLE::Warn = 3;
    >
    > my $word;
    > eval {
    > $word = Win32::OLE->GetActiveObject('Word.Application');
    > };
    >
    > die "$@\n" if $@;
    >
    > unless(defined $word) {
    > $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit })
    > or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n";
    > }
    >
    > $word->{Visible} = 1;
    > my $doc = $word->Documents->Add;
    >
    > my $selection = $word->Selection;
    > $selection->Range->ListFormat->ApplyBulletDefault;
    > $selection->TypeText("Hello World");
    > $selection->TypeParagraph;
    > $selection->TypeText("How do you feel today");
    > $selection->TypeParagraph;
    >
    >
    > sleep 10;
    >
    >
    > __END__
    >
    >
    > Sinan
    > --
    > A. Sinan Unur <>
    > (reverse each component and remove .invalid for email address)
    >
    > comp.lang.perl.misc guidelines on the WWW:
    > http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


    Thanks, Sinan. As you suggested, I tried the simplest possible macro
    to produce a bulleted list. It revealed the Range, ListFormat,
    ApplyBulletDefault methods. Thanks for showing me how to apply these
    within Perl. I should now be able to finish my work.

    JR
    jr, Feb 7, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Fields

    need help with bulleted lists

    Eric Fields, Feb 23, 2004, in forum: HTML
    Replies:
    9
    Views:
    413
    Jukka K. Korpela
    Feb 24, 2004
  2. Patrick.O.Ige

    Ole ole

    Patrick.O.Ige, Jul 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    476
    Patrick.O.Ige
    Jul 16, 2006
  3. Drew Pihera
    Replies:
    0
    Views:
    620
    Drew Pihera
    Feb 4, 2004
  4. Lance Hoffmeyer
    Replies:
    0
    Views:
    228
    Lance Hoffmeyer
    Nov 17, 2003
  5. Dave

    win32::OLE::Excel and lists

    Dave, Jun 17, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    343
    A. Sinan Unur
    Jun 21, 2005
Loading...

Share This Page