Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
How-Perl-saved-the-day today.

The problem: SQL tables and procedures are documented in the source code and now we want to include a subset of them in a written introduction/tutorial. Copying the text into the Word document is bound to make them go out of sync. And it's boring...

The solution: A little script to extract the documentation and write it to small Word files, grouped by sub system. These word files are then linked into the main document, so they can be re-generated independently from the main document.

Making it happen: At first I thought RTF would be the right choice for this , but that just ended up being messy, and I didn't have time to get to know the RTF format. So I turned to automating Word instead. Surprisingly, I couldn't find a simple wrapper around the Win32::OLE module, so I hacked something together using example code from the Net.

The code: Now I have an extremely simplistic module that does the not-so-heavy lifting. This is basically it:

package Word::Document::Writer; use Data::Dumper; use Class::MethodMaker new_with_init => "new", get_set => [ "oWord", "oDocument", "oSelection", "hasWritten" +]; sub init { my $self = shift; my (%hParam) = @_; $self->hasWritten(0); $self->oWord( Win32::OLE->new('Word.Application', 'Quit') ) or die +("Could not create OLE Word: $!\n"); $self->oDocument( $self->oWord->Documents->Add ) or die("Could not + add Word document\n"); $self->oSelection( $self->oWord->Selection ) or die("Could not get + Word selection\n"); return; } sub WriteText { my $self = shift; my ($text, $level) = @_; $level ||= 0; my $style = $level ? "Heading $level" : "Normal"; $self->oSelection->TypeParagraph if($self->hasWritten); $self->hasWritten(1); $self->oSelection->TypeText($text); $self->oSelection->{Style} = $style; return(1); } sub SaveAs { my $self = shift; my ($file) = @_; return( $self->oDocument->SaveAs($file) ); } __END__

I can use it like so:

my $oDocument = Word::Document::Writer->new(); $oDocument->WriteText("A level 1 Heading", 1); $oDocument->WriteText("Basic Normal paragraph"); $oDocument->SaveAs("mydocument.doc");

The new problem: What do I do with this code?

It solves an actual problem, but the problem wasn't very difficult to solve. So it hardly does anything while being very useful in my little script. Is it useful enough to merit a CPAN upload (after adding POD and tests obviously)?

If it is, what namespace should I use? Hogging the namespace for this puny module seems almost rude. While Word::Document::Writer::Simple is an option, most other *::Simple modules are supposed to be simple to use, and a more proper name would be Word::Document::Writer::Simplistic :) But that sounds ridiculous.

So, rude or ridiculous? Or something completely different?

/J


In reply to Module advice: when is it too insignificant to release? by jplindstrom

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (7)
    As of 2014-04-19 05:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (478 votes), past polls