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__