Adithyakiran.k has asked for the wisdom of the Perl Monks concerning the following question:
I have to convert a xml file to MS Word Document. I have predefined styles in a .dotx file which should be applied to the text extracted from the XML. Like there are specific styles to "Title", "Paragraphs", "Lists", etc.,. I am using win32::ole to create MS Word Document. I am not able to get the footnote references at the places I want them to be. Please suggest how can I get the footnotes at right places in the Word document. Please see the below code.
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 secon +d 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');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to add a footnote in MS Word using win32::ole
by hdb (Monsignor) on Aug 28, 2013 at 11:13 UTC | |
by Adithyakiran.k (Novice) on Sep 12, 2013 at 11:59 UTC | |
by Adithyakiran.k (Novice) on Nov 07, 2013 at 15:02 UTC | |
|
Re: How to add a footnote in MS Word using win32::ole
by Anonymous Monk on Aug 28, 2013 at 00:22 UTC | |
by Anonymous Monk on Aug 28, 2013 at 04:44 UTC | |
by Anonymous Monk on Aug 28, 2013 at 07:59 UTC |