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');

In reply to How to add a footnote in MS Word using win32::ole by Adithyakiran.k

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.