Oh, Sorry for misinterpretation. I'm still trying to handle reading a Word
Document fully. After that only I'll focus on involved in writing back. May
be your case will help me by then.

Yours,
Shamal

On Mon, May 17, 2010 at 3:27 PM, MSB <[email protected]> wrote:

>
> Thanks, yes, we now that you can do that but the quesion was 'how can I
> modify existing footers and insert new footers into a document' not how can
> I read the contents of same.
>
> Yours
>
> Mark B
>
>
> Shamal Karunarathne wrote:
> >
> > There's HeaderStories in HWPF. You can extract headers and footers using
> > that. It's clean and clear. Tell me if you can't retrieve.
> >
> > On Mon, May 17, 2010 at 3:06 PM, <[email protected]> wrote:
> >
> >> HI Mark,
> >>
> >> Thanks for your help. I'm also trying to run your program but I'm unable
> >> to
> >> find the jars. I used POI-3.6 jar but I didn't find the required
> classes.
> >> Can you please provide the jar for below program? So that I can do some
> R
> >> &
> >> D on this issue.
> >>
> >> Thanks & Regards,
> >> Madhusudan Reddy
> >> JAVA | HDC | Accenture
> >> M. No: 9966601155
> >>
> >> -----Original Message-----
> >> From: MSB [mailto:[email protected]]
> >> Sent: Sunday, May 16, 2010 8:54 PM
> >> To: [email protected]
> >> Subject: Re: Need help in updating footer of Word Document
> >>
> >>
> >> Only just begun to have a play with XWPF but it already seems much more
> >> 'solid' that HWPF as the latter is sorely in need of talented developers
> >> to
> >> help move it on (not too subtle hint there in case you missed it).
> >>
> >> However, the news on footers - and on headers for that matter - is still
> >> not
> >> too good. The XWPFDocument class defines a method that allows you to
> >> recover
> >> the documents associated XWPFHeaderFooterPolicy object. That object is
> >> responsibile for managing the documents headers and footers and it
> >> contains
> >> method that allow you to create a new footer, recover a reference to a
> >> footer and to then modify that. The only problem I have run in to yet is
> >> that I cannot get at this object the XWPFHeaderFooterPolicy that is. So
> >> far,
> >> I have tried to call the gerHeaderFooterPolicy() on an XWPFDocument that
> >> I
> >> had previously created in the code and a null value was returned.
> >> Thinking
> >> about HWPF and the typical idion we use there when getting cells, I
> >> though
> >> that I should test the returned value and if it was null, then reate a
> >> new
> >> instance of the XWPFHeaderFooterPolicy class. This still did not work
> and
> >> the code still threw a NullPointerException. Finally, I though I would
> >> create a blank document using Word and insert a footer into that,
> >> planning
> >> to open it using POI and then get the header/footer policy and so on
> from
> >> there. However, now an exception was thrown when I tried to create an
> >> instance of the XWPFDocument class, this time the message concerned a
> >> null
> >> XWPFHeaderFooterPolicy object - surprise!
> >>
> >> So, the next thing I am going to try is to download the very latest
> >> release
> >> of the software and try that. As always, I will keep you updated if I
> >> make
> >> any progress. If you want to follow in my footsteps so to speak, this is
> >> the
> >> scruffy test code I have been playing around with;
> >>
> >> import org.apache.poi.xwpf.usermodel.*;
> >> import org.apache.poi.xwpf.model.*;
> >>
> >> import java.io.File;
> >> import java.io.FileInputStream;
> >> import java.io.FileOutputStream;
> >> import java.io.IOException;
> >>
> >> /**
> >>  *
> >>  * @author win user
> >>  */
> >> public class Main {
> >>
> >>    public void createDocument(String documentName, String
> documentFolder)
> >> {
> >>        File file = null;
> >>        FileInputStream fis = null;
> >>        FileOutputStream fos = null;
> >>        XWPFDocument document = null;
> >>        XWPFHeaderFooterPolicy hfPolicy = null;
> >>        XWPFFooter footer = null;
> >>        XWPFParagraph[] footerParas = null;
> >>        XWPFParagraph para = null;
> >>        XWPFRun run = null;
> >>
> >>        try {
> >>            document = new XWPFDocument();
> >>
> >>            para = document.createParagraph();
> >>            run = para.createRun();
> >>            run.setText("This should contain the text for the first
> >> XWPFRun
> >> " +
> >>                    "in the newly created Paragraph.");
> >>            run.setBold(true);
> >>            run = para.createRun();
> >>            run.setText("It is my hope that this XWPFRun will contain the
> >> "
> >> +
> >>                    "text for the second paragraph that I have just added
> >> -
> >> " +
> >>                    "with luck - to the newly created document.");
> >>
> >>            hfPolicy = document.getHeaderFooterPolicy();
> >>
> >>            if(hfPolicy == null) {
> >>                hfPolicy = new XWPFHeaderFooterPolicy(document);
> >>            }
> >>
> >>            hfPolicy.createFooter(
> >>
> >>
> >>
> rg.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr.Enum.forString("Footer."));
> >>
> >>            file = new File(documentFolder, documentName);
> >>            fos = new FileOutputStream(file);
> >>            document.write(fos);
> >>        }
> >>        catch(Exception ex) {
> >>            System.out.println("Caught an: " + ex.getClass().getName());
> >>            System.out.println("Message: " + ex.getMessage());
> >>            System.out.println("Stacktrace follows:.....");
> >>            ex.printStackTrace(System.out);
> >>        }
> >>        finally {
> >>            if(fos != null) {
> >>                try {
> >>                    fos.close();
> >>                }
> >>                catch(IOException ioEx) {
> >>                    // I G N O R E
> >>                }
> >>            }
> >>        }
> >>
> >>    }
> >>
> >>    /**
> >>     * @param args the command line arguments
> >>     */
> >>    public static void main(String[] args) {
> >>        new Main().createDocument("New XWPF Document.docx", "C:/temp");
> >>    }
> >> }
> >>
> >> What it does show is how easy it is to use XWPF to create documents.
> >>
> >> Yours
> >>
> >> Mark B
> >>
> >>
> >> madhusudan.reddy wrote:
> >> >
> >> > Hi,
> >> >
> >> > We are using ApachePOI for creating word documents dynamically using
> >> java
> >> > in our application. We are wondering if we have a better way to handle
> >> the
> >> > header and footers in the word document dynamically.
> >> >
> >> > Need information or pointers to implement any of hte following things:
> >> > 1) Addition of new footer/header dynamically in the word document.
> >> > 2) Updating an existing footer/header dynamically in the word
> document.
> >> >
> >> > Any pointers would be very helpful.
> >> >
> >> > Thanks & Regards,
> >> > Madhusudan Reddy
> >> > JAVA | HDC | Accenture
> >> > M. No: 9966601155
> >> >
> >> >
> >> > This message is for the designated recipient only and may contain
> >> > privileged, proprietary, or otherwise private information.  If you
> have
> >> > received it in error, please notify the sender immediately and delete
> >> the
> >> > original.  Any other use of the email by you is prohibited.
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/Need-help-in-updating-footer-of-Word-Document-tp28566396p28575351.html
> >> Sent from the POI - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
> >>
> >>
> >> This message is for the designated recipient only and may contain
> >> privileged, proprietary, or otherwise private information.  If you have
> >> received it in error, please notify the sender immediately and delete
> the
> >> original.  Any other use of the email by you is prohibited.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Need-help-in-updating-footer-of-Word-Document-tp28566396p28580194.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to