use warnings; use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft.Word'; # wd constants use Win32::OLE::Const 'Microsoft Office'; # mso constants my $cur_style = 'a'; my $cur_bookmark = 'a'; sub bold { my $document = shift; my $bold = shift; $document->ActiveWindow->Selection->{Font}->{Bold} = $bold ? -1 : 0; } sub save_doc_as { my $document = shift; my $filename = shift; $document->SaveAs($filename); } sub create_style { my $document = shift; my $fontname = shift; my $font_size = shift; my $bold = shift; my $italic = shift; my $style = $document->Styles->Add($cur_style); my $style_font = $style->{Font}; $style_font -> {Name } = $fontname; $style_font -> {Size } = $font_size; $style_font -> {Bold } = $bold; $style_font -> {Italic} = $italic; my %style; $style{name} = $cur_style++; return \%style; } sub set_style { my $document = shift; my $style_arg = shift; $document->ActiveWindow->Selection -> {Style} = $style_arg -> {name}; } sub text { my $document = shift; my $text = shift; $document->ActiveWindow->Selection -> TypeText($text); } # aka new line, newline or NL sub enter { my $document = shift; $document->ActiveWindow->Selection -> TypeParagraph; } my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add('new.dotx',0,0,-1); # selection is the insertion point. my $selection = $word->Selection; $selection->{Style}="Title" ; text($document, "135: This is the Document Title"); text($document,"\n"); $selection->{Style}="Normal" ; bold($document, 1); text($document, "Authors:"); bold($document,0); enter($document); text($document, "some text ............"); #---------------------------------------- #Insert Footnote Here $selection->Footnotes->Add($selection->{Range},"1", "This is the First Footnote"); #---------------------------------------- text($document, "some other text ........."); #---------------------------------------- #Insert Footnote Here $selection->Footnotes->Add($selection->{Range},"2", "This is the second Footnote"); #---------------------------------------- enter($document); bold($document, 1); text($document, "Introduction"); bold($document,0); enter($document); text($document, "This will have the introduction .... "); $selection->{Style}=" :000" ; text($document, "Quick Look"); $selection->{Style}="Normal" ; enter($document); text($document, "This is the Normal Paragraph Data"); save_doc_as($document, 'output.docx');