Return-Path: Delivered-To: apmail-poi-user-archive@www.apache.org Received: (qmail 33884 invoked from network); 17 May 2010 07:11:23 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 May 2010 07:11:23 -0000 Received: (qmail 59022 invoked by uid 500); 17 May 2010 07:11:22 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 58956 invoked by uid 500); 17 May 2010 07:11:22 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 58948 invoked by uid 99); 17 May 2010 07:11:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 May 2010 07:11:22 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=AWL,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of shamalk@gmail.com designates 209.85.212.46 as permitted sender) Received: from [209.85.212.46] (HELO mail-vw0-f46.google.com) (209.85.212.46) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 May 2010 07:11:17 +0000 Received: by vws9 with SMTP id 9so1542041vws.33 for ; Mon, 17 May 2010 00:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type; bh=x0Zx9708jYi1KW+it6pI3nIF+2HAg19pa/XOO3BfAWA=; b=cRUVuBQpIPiC1wchO5hE3PxsoslOFoXVlEBMsEgPgXazQy51maMShENYo9jSVV2Jn4 QecuByVAnaFuGfqLo66rswbXldpnHM5YLL6j1ORQHdkmK54uwDw3Iimtquze6O34itr8 NcXbcC6+J0vMBgFBNc1nuGgfivrM2cyPk2Lek= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=SaHKAxlUEm7AF+XmTAISObusycjT86yx5yv+KVbmCrvO2M1CsJTS9LVSz7r5Lz7ZX3 9VLgSWJzDDSd15BOdULZnnHCAtoeOEwYULyDoopF29379P4J/+WbEYCKuDis9bn/FfY8 c6u9r9tmD7u6SVWPvMFUhZ8kAchj2zOpxqbyw= Received: by 10.220.128.136 with SMTP id k8mr2339112vcs.58.1274080256213; Mon, 17 May 2010 00:10:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.96.6 with HTTP; Mon, 17 May 2010 00:10:36 -0700 (PDT) In-Reply-To: References: <28575351.post@talk.nabble.com> From: Shamal Karunarathne Date: Mon, 17 May 2010 15:10:36 +0800 Message-ID: Subject: Re: Need help in updating footer of Word Document To: POI Users List Content-Type: multipart/alternative; boundary=e0cb4e8875891643300486c4ed7b --e0cb4e8875891643300486c4ed7b Content-Type: text/plain; charset=ISO-8859-1 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, 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:markbrdsly@tiscali.co.uk] > Sent: Sunday, May 16, 2010 8:54 PM > To: user@poi.apache.org > 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: user-unsubscribe@poi.apache.org > For additional commands, e-mail: user-help@poi.apache.org > > > > > 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: user-unsubscribe@poi.apache.org > For additional commands, e-mail: user-help@poi.apache.org > > --e0cb4e8875891643300486c4ed7b--