I am trying to read a word document template and then replace the variables from the template, with user given data.without changing the heading or style as on the tempate.I'm not sure that what I am doing is correct way or not but this is the way I started:
'XWPFDocument docx = new XWPFDocument(
new FileInputStream(
"D://TestDocumentPrep/src/XXXXX_TestReport_URL_Document.docx"));
XWPFWordExtractor we = new XWPFWordExtractor(docx);
String textData = we.getText();
String newTestData=textData.replace("$var_source_code$", list.get(1))
.replace("$var_rsvp_code$", list.get(2))
.replace("$var_ssn$", list.get(3))
.replace("$var_zip_code$", list.get(4))
.replace("$var_point_for_business$",
anotherData.getPointForBusiness())
.replace("$var_E1_url$", anotherData.getE1url())
.replace("$var_E2_url$", anotherData.getE2url())
.replace("$var_E3_url$", anotherData.getE3url());
System.out.println(newTestData);'
This is what I have done.But Its reading the content of the word document as a string and replacing the variables.Now how to put the replaced string in word document in the template format?
Here I found something but Not exactly my solution
Here also I found something but not exact solution