Hi all!
I have written a module for creating MS Word documents using the Win32::OLE module. It's a wrapper for getting things done a little more easily than using the DOM directly, and it has quite a few workarounds to bugs and problems with Word.
Anyway, what I'm most interested in now is name suggestions. My currently best idea is:
Win32::Word::Document::Writer
It's a bit long, but there are reasons for all the parts:
Win32 - because it's windows specific (but happens to be an implementation detail, so I wouldn't mind losing it).
Document::Writer - Writer because it follows the tradition of RTF::Writer and a lot of other modules. And I'd like to not hog the entire Word::Document namespace.
Word::Document - Document, because there may be other Word::* modules like... I don't know... Word::Dotfile or something.
Any ideas on this?
FYI:
There is also another module, Win32::Word::Document::Converter::FromHTML, which converts a HTML document to a Word document, and Win32::Word::Document::Converter::FromWeb which uses FromHTML to convert many web pages to a single Word document.
FYI:
This is the SYNOPSIS section. But looking at the interface, I'm inclined to simplify and unify it a little.
use Win32::Word::Document::Writer; my $oWriter = Win32::Word::Document::Writer->new();
#Adding text and paragraphs with different styles $oWriter->WriteParagraph("Example document", 1); #Heading 1 $oWriter->WriteParagraph("Usage", 2); #Heading 2 $oWriter->WriteParagraph("Write sentences to the document using a"); #Normal $oWriter->WriteParagraph("heading level, or Normal if none is specified. "); #newline: new paragraph
$oWriter->Write("Add some more text the current paragraph");
$oWriter->NewParagraphStyle("Envelope Return"); #The style must exist $oWriter->Write("Return to sender. ");
$oWriter->SetStyle("Envelope Address"); #Change the current style $oWriter->Write("Nope, we changed the style of the entire paragraph"); $oWriter->Write("to a footer style");
#Setting character styles $oWriter->WriteParagraph("Some more normal text. "); $oWriter->SetStyle("Hyperlink"); #A charachter style $oWriter->Write("http://www.DarSerMan.com/Perl/"); $oWriter->ClearCharacterFormatting(); #Clear character style $oWriter->Write(" <-- my ");
#Bold/Italics $oWriter->ToggleBold(); #Toggle bold $oWriter->Write("Perl "); $oWriter->SetItalic(1); #Turn on Italic $oWriter->Write("stuff."); $oWriter->ToggleItalic(); #Toggle Italic $oWriter->SetBold(0); #Turn off bold
#Bullet point lists $oWriter->ListBegin(); $oWriter->ListItem(); $oWriter->Write("The first bullet item"); $oWriter->ListItem(); $oWriter->Write("The second bullet item");
$oWriter->ListBegin(); #Nested bullet point list $oWriter->ListItem(); $oWriter->Write("The first inner bullet item"); $oWriter->ListItem(); $oWriter->Write("The second inner bullet item");
$oWriter->ListEnd(); $oWriter->ListEnd();
#Do this at regular intervals (say, every couple of 10K of text you add) $oWriter->Checkpoint();
#Tables $oWriter->WriteParagraph("Table example", 1); $oWriter->NewParagraphLevel(0);
$oWriter->TableBegin(); $oWriter->TableRowBegin(); $oWriter->TableColumnBegin(); $oWriter->SetBold(1); $oWriter->Write("HTML table"); $oWriter->TableColumnBegin(); $oWriter->Write("Win32::Word::Document::Writer");
$oWriter->TableRowBegin(); $oWriter->TableColumnBegin(); $oWriter->SetBold(0); $oWriter->Write("<table>"); $oWriter->TableColumnBegin(); $oWriter->Write("TableBegin()");
$oWriter->TableRowBegin(); $oWriter->TableColumnBegin(); $oWriter->Write("<tr>"); $oWriter->TableColumnBegin(); $oWriter->Write("TableRowBegin()");
$oWriter->TableEnd();
#Save the document $oWriter->SaveAs("01example.doc");
/J -------- ------ ---- --- -- -- -- - - - - - Johan Lindström Sourcerer @ Boss Casinos johanl AT DarSerMan.com
Latest bookmark: "TCP Connection Passing" http://tcpcp.sourceforge.net/ dmoz: /Computers/Programming/Languages/JavaScript/ 12
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs