a text/xml declaration may occur only at the very beginning of input in word while using POI



I am creating an word document using Apache POI when i am running my code as a main program it is running fine and creating the word document with the header footer but when i am trying to add it in my web application then it is showing error that,a text/xml declaration may occur only at the very beginning of the document.I am using POI 3.10 jar.Here is my code i am posting



XWPFDocument document = new XWPFDocument();

CTP ctp = CTP.Factory.newInstance();
CTR ctr = ctp.addNewR();
CTRPr rpr = ctr.addNewRPr();
CTText footerText = ctr.addNewT();

//writing Footer Text for each page
footerText.setStringValue("Client Service Contact:Tomas.Layrisse@mshgroupconsulting.com 990765432");

XWPFParagraph footerParagraph = new XWPFParagraph(ctp, document);
XWPFParagraph[] setfooterTexts = new XWPFParagraph[1];

setfooterTexts[0]=footerParagraph;

CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
XWPFHeaderFooterPolicy headerFooterPolicy = new XWPFHeaderFooterPolicy(document, sectPr);

//setting footer to each page

headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, setfooterTexts);

String contentType="application/msword";
response.addHeader("Content-Disposition", "attachment; filename=\""+ "reportName" + ".docx\"");
response.setContentType(contentType);
ServletOutputStream out = response.getOutputStream();
document.write(out);


somebody please help me ..


No comments:

Post a Comment