Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2021-09-22 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?