You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Najia <na...@btpplus.com> on 2013/10/16 05:51:15 UTC

How to get all Header data with multiple pages and multiple paragraphs

Hi,
I'm generating a docx file and in that file I need to replace the tokens.
Rest of my work is going fine with token replacement in document, but the
code doesn't replace header tokens. I'm using the following code to get
header data but when I use .getDefaultHeader(),it picks only second page
header data which is in the center. And using by  Paragraph, only one line
text is coming in paraList. In my case few tokens are on left side and some
are on right side and in different lines. Please guide me how to handle it.

		XWPFHeaderFooterPolicy headerFooterPolicy =
document.getHeaderFooterPolicy();
		XWPFHeader defaultHeader = headerFooterPolicy.getDefaultHeader();	
//		XWPFHeader defaultHeader =document.getHeaderList().get(1); 			
			
		System.out.println("Header value is : " + defaultHeader.getText()); 			
			
	        List<XWPFParagraph> paraList = null;
	        List<XWPFRun> runList = null;	        
	        XWPFRun run = null;
	        Iterator<XWPFRun> runIter = null; 
	        Iterator<XWPFParagraph> paraIter = null; 
	        XWPFParagraph para = null; 
	        paraList = defaultHeader.getListParagraph(); 
	        paraIter = paraList.iterator(); 
//	        CTHdrFtr hdrftr = paraList.get(0);

	        // Replace token in plain paragraph
	       
	        String temp = "";
	        int tempPosition = -1;
	        List<Integer> runTextPositions = new ArrayList<Integer>();
	        
	        while(paraIter.hasNext()) { 
	            para = paraIter.next(); 
	            runList = para.getRuns();
	            runIter = runList.iterator(); 



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-get-all-Header-data-with-multiple-pages-and-multiple-paragraphs-tp5713951.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org